Poco learning for entity framework 4

Source: Internet
Author: User

For more information about the features of Entity Framework 4, see this article. net 4 Entity Framework introduction, one of the most interesting is the support for poco: EF4 provides simple and traditional CLR object (plain old CLR object/POCO) support for entities. Your object can exist independently of EF, which better supports test-driven development and domain-driven design ). At the same time, EF can still help track changes to poco entities, allow delayed loading, and automatically correct changes to navigation properties and Foreign keys.

Entity Framework 1.0 has been released for a long time, but it seems that few people are using it. One of the major reasons may be that Poco is not supported. At least I think so without using ef1. Entity Framework 4.0 (also known as EF V2) will provide poco support, for many people, this is the time to start using the Entity Framework.

The best way to learn is to practice it. Today I spent most of my time following this article [translation] using the repository and unit of work modes in Entity Framework 4.0, there are three poco series in this article. Although the article was written in EF4 beta1, it is now RC, which is equally effective:

Poco in Entity Framework: Part 1-the experience ([translation] poco support in Entity Framework-Part 1-experience)

Poco in Entity Framework: Part 2-complex types, deferred loading and explicit loading ([translation] poco support in Entity Framework-Part 2-complex types, delayed loading and explicit loading)

Poco in Entity Framework: Part 3-change tracking with poco ([translation] poco support in Entity Framework-Part 3-poco change tracking)

In this article, EF 4-implementing poco objects is illustrated in detail.

Here are some notes for the learning process:

  • The Automatic code generation function must be disabled.
  • The parameters of the inherited objectcontext constructor are actually the connection string of the specified database connection string.
  • The edmx connection string generated by the tool is saved only in APP. config of the Assembly. Remember to copy it to the related app. config or web. config.
  • Because there is no CSDL or SSDL, the table name and column name on the model in edmx must be consistent with your poco name. Entity Framework 4.0 introduces a convention-based ing to allow ing of entity types, attributes, complex types, and relationships to a conceptual model without explicit modifiers. A simple rule is that the object type name, attribute name, and complex type name used in your poco class must match the corresponding names defined in the conceptual model.
  • Unit testing of code is very important.
  • To set the delayed loading attribute to virtual, set contextoptions. lazyloadingenabled = true on objectcontext.
  • The support for enumeration types is achieved through complex types, you can refer to the article http://blogs.msdn.com/alexj/archive/2009/06/05/tip-23-how-to-fake-enums-in-ef-4.aspx

Tip 53-how to debug EF poco mapping issues: http://blogs.msdn.com/alexj/archive/2010/02/12/tip-53-how-to-debug-ef-poco-mapping-issues.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.