New Entity Framework Feature CTP for VS2010 Beta 2

The EF team just released the newest version of the Feature CTP that is now compatible with VS2010 Beta2. Hooray for compatibility, but more importantly, we can now work with a greatly enhanced version of the Code Only feature and Self-Tracking Entities. Code-Only is the API that allows you to use EF without a model at all. Self-Tracking Entities provides tracking for entities across WCF Services and their clients .

I’ll talk a bit about Code Only here, which will be of great interest to Domain Driven  Developers.

Under the covers, EF depends on the metadata for a model. Code Only will create this metadata on the fly based on your classes.

Code Only uses convention over configuration. First with convention, it builds the metadata using whatever it finds in your classes combined with a set of assumptions. However, you can do some major tweaking to those assumptions and force it, through configuration, to define the metadata more to your liking. there are two important benefits to this. the first is that if you are leveraging code-only’s ability to generate DDL and therefore define your database schema, you can have more control over how inheritance is "translated” in to tables, more control over attributes of columns, tables and constraints as well as constraints between tables.

The configuration is not done through attributes, but through code.

Here’s a very simple example.

By convention, Code Only will use any property named “ID” as an identifying property (EntityKey) as well as the presumed primary key in the back end data store. However, if you don’t happen to follow this pattern in naming your identity properties, then you can instruct code only which property to use as the identifier.

ContextBuilder is the class that knows how to build the ObjectContext and metadata from your classes.

This code modifies how the entity for the Category class should be configured beyond the initial assumptions. Specifically, it uses the HasKey property to define that the CID property should be used as the key rather than ID (which doesn’t exist in the Category class).

builder.Entity<Category>()
            .HasKey(c => c.CID);

This is merely the tip of the iceberg.

The ADO.NET team has a list of improvements to Code Only and Self-Tracking Entities to look for and will be providing detailed walkthroughs of the new features in their blog post ADO.Net Entity Framework Community Technology Preview Released!

You can get the new bits here: update of the Entity Framework Feature CTP

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

3 thoughts on “New Entity Framework Feature CTP for VS2010 Beta 2

  1. Is it possible to have EF4 create a database on the fly at runtime based on the model? I understand they have a wizard that you can do this in VS 2010 but I’m talking about runtime, when the app realizes that the database isn’t present. Many smaller applications could use this functionality to make deployment easier.

  2. Thanks for the link to ADO.Net. I’m still learning how to write good scripts and I found there very helpful community:) This Code Only is a bit complicated to me so any new source of information is very helpful.

Leave a Reply to admin Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.