EF Feature CTP4 Released!

 


The information in this post is out of date.

Visit msdn.com/data/ef for the latest information on current and past releases of EF.


 

We’ve release an updated Entity Framework Feature Community Technology Preview (CTP) which is available for download. This is our fourth CTP and includes updates to the Code First feature along with the first preview of our Productivity Improvements for EF.

Feature CTP4 contains a preview of new features that we are considering adding to the core framework in the future and would like to get community feedback on. Feature CTP4 builds on top of the existing Entity Framework 4 (EF4) functionality that shipped with .NET Framework 4.0 and Visual Studio 2010.

Getting Started

We’ve created a couple of walkthroughs to get you started with these new features, we’ll also be providing more detailed posts that dive down into interesting areas of each feature in the coming weeks.

If you need assistance with CTP4 we have an Entity Framework Pre-Release Forum.

Productivity Improvements

We recently posted here about a set of productivity improvements we have been working on to simplify the process of writing data access code with the Entity Framework. CTP4 includes the core API surface and functionality that is described in the post. We’d love to hear your feedback on this simplified experience, be sure to check out the walkthrough.

Code First

Updates and enhancements to Code First include:

  • Moved to the System.Data.Entity.ModelConfiguration namespace
  • Refactored ContextBuilder into ModelBuilder and DbModel
    ModelBuilder is a high level component that lets you tweak a model, ModelBuilder then produces an immutable DbModel that can be used to construct a context. In the future DbModel will become a fundamental component of the EF stack as we look at other ways to build models beyond ModelBuilder.
  • More Model Discovery Conventions
    We posted details about the complete set of conventions we plan to support here
    In CTP4 we have implemented the following conventions:
    • Primary Key
    • Relationship Inverse
    • Foreign Key
    • Pluralization of Table Names
  • Support for Data Annotations
    We posted details about all the Data Annotations we plan to support here
    The annotations supported in CTP4 are:
    • Key
    • StringLength
    • ConcurrencyCheck
    • Required
    • Timestamp
    • DataMember
    • RelatedTo
    • MaxLength
    • StoreGenerated
  • Parameterless overload of MapSingleType()
    This allows you to configure table names without having to explicitly map every property
  • Improved Relationship Configuration API
    We’ve made some changes to the Fluent API methods used to configure relationships to make the API more explicit and intuitive. These changes are covered in the Code First Walkthrough .

Road Map

We are still working through the best ship vehicle to deliver a go-live release for these features. Your feedback has had a big impact on the Code First feature so far and we want to be careful not to lock down the API too quickly. That said we are getting consistent asks for a go-live for Code First and we are working to get to an RTM in the earliest feasible ship vehicle.

 

Please keep the feedback coming!

ADO.NET Entity Framework Team

Comments

  • Anonymous
    July 14, 2010
    What are your plans to support new Datatypes e.g. HierarchyID and spatial data

  • Anonymous
    July 14, 2010
    I wonder if you're going to introduce normal lazy collection filtering, when someComponent.SomeCollection.Take(5) would not load the whole list from the DB.

  • Anonymous
    July 14, 2010
    New guy has to ask...  What the heck is a CTP?   Not everyone was around for the first 3, so while I celebrate the release of CTP4, I have no clue what it is.   Scott Hanselman linked me here from his blog and I am glad he didn't just call it the EF MUE or I would be even more lost.   At some point I will intuatively know what CTP, BFG, QRW and such will mean, but until I get more hours under my belt, I still wonder...   What the heck is a CTP?!?!

  • Anonymous
    July 14, 2010
    I must admit I haven't been following this closely but I always assumed that the RTM version of Visual Studio 4.0 and the .NET 4.0 framework included the RTM version of EF4.  I take it I am wrong?

  • Anonymous
    July 15, 2010
    @noob.net, CTP stands for Community Technical Preview.  Basically it means something kind of like a beta but not quite as finalized as that.  :-)  We're putting this release out there to make it clear the direction we're heading and to get feedback.  We'll take that feedback, do more testing and development on our own and then work the results into some future final product release.  Part of the point of naming it a CTP is to make it clear that the API is likely to evolve some before we get things in the final shape for a "real" release. @e36M3, You are absolutely right.  The RTM version of VS2010/.net4 does include the RTM version of EF4.  This is the fourth CTP release of a set of additional features above and beyond what shipped with EF4.  (In this case the 4 in CTP4 is just a coincidence and has nothing to do with the version number of EF4.)  These additional features will be part of a future RTM release of EF.

  • Danny
  • Anonymous
    July 15, 2010
    Thanks for clarifying this Danny.  So the CTPs will culminate at a service pack or something like that?  I guess I always thought of CTPs as something pre RTM, which I suppose as you've said is right, it's just RTM could be a new version or a service pack, etc.

  • Anonymous
    July 15, 2010
    Thanks for clarifying this Danny.  So the CTPs will culminate at a service pack or something like that?  I guess I always thought of CTPs as something pre RTM, which I suppose as you've said is right, it's just RTM could be a new version or a service pack, etc.

  • Anonymous
    July 15, 2010
    congrats on the new release. I don't know if this is the place to ask or if it's asked in a different place but are you planning support for custom facets for properties? It would be nice if the conceptual model could be extended like this: <EntityType ........> <Property ......>  <Facets>    <Facet Name="MinumumLength" Value="5"/>    <Facet Name="MyFacet" Value="SomeValue"/>  </Facets> </Property> </EntityType> With support in the designer in using custom POCO templates, everybody is free to implement features beyond the basics like null-able. The facets can be implemented as a simple dictionary of name and value. It should be relatively easy to add to the designer (I think ;) ) and gives everybody a single location for the description a property.

  • keep up the good work, André
  • Anonymous
    July 15, 2010
    @Danny: Is there support for "one-way" many-to-many like here social.msdn.microsoft.com/.../6920db2b-88c7-4bea-ac89-4809882cff8f Also - Where is the ability to map the StoreTableName like with CTP3?

  • Anonymous
    July 15, 2010
    @TheCloudlessSky Yes this is supported with a parameterless overload of the WithXXX relationship methods:   modelBuilder.Entity<Post>().HasMany(p => p.Tags).WithMany(); The syntax for specifying table names is the same as in CTP3, we also introduced a parameterless overload of MapSingleType so you don't have to explicitly map every column just to rename the table:    modelBuilder.Entity<Category>().MapSingleType().ToTable("CategoryTable");

  • Anonymous
    July 15, 2010
    for releases like this can you put a reminder at the top to tell people where this product sits in the roadmap / or in relation to other products at first i didnt know if this is a new version of the core entity framework stuff, or something new, does this replace whats in VS2010 - is it an extension? etc. thanks!

  • Anonymous
    July 15, 2010
    Do you plan to extend the supported data types? Basically inline with the first comment. Thanks!

  • Anonymous
    July 15, 2010
    @Rowan: It would be nice that there was an IDatabaseInitializer for DbContext that never creates the database from the model. I really don't like that I can't have our DBA create the DB and have to have the extra EdmMetadata table. That's very annoying. Maybe I want to map the model to an existing database. Is there currently a way to do this?

  • Anonymous
    July 15, 2010
    @Danny: Thank you!  Acronynms can be very frustrating when a person is trying to learn new technologies.  I agree with @simon about putting a reminder at the top and while it may be redundent to many, maybe a sentence or two in new programmer terms about the topic. Thank you!

  • Anonymous
    July 15, 2010
    Right now I created a "NonDatabaseInitializer" that implements IDatabaseInitializer that doesn't do anything in the "InitializeDatabase" method and I'm able to query the DB without checking if the database is valid.

  • Anonymous
    July 15, 2010
    With CTP4 I can't initialize ConcurrencyToken property. Property(e => e.ConcurrencyToken) .IsRequired() .IsConcurrencyToken() .HasStoreType("rowversion") .StoreGeneratedPattern = {System.Data.Metadata.Edm.}StoreGeneratedPattern.Computed; How can I access to System.Data.Metadata.Edm namespace? Microsoft.Data.Entity.CTP.dll don't contains him.

  • Anonymous
    July 15, 2010
    About previous post: I found StoreGeneratedPattern enum in System.Data.Entity.dll :) Thanks

  • Anonymous
    July 15, 2010
    @Rowan: When I do something like:    modelBuilder.Entity<User>.HasMany(u => u.Profile).WithMany().HasConstraint((u, p) => u.DefaultProfileId == p.Id) the query is expecting each Profile to have a "User_Id" property. How can I avoid this so that Profiles are "independent" of Users (except the many-to-many relationship)?

  • Anonymous
    July 16, 2010
    Just a note...the u.Profile should be u.DefaultProfile

  • Anonymous
    July 16, 2010
    Nevermind my previous posts, I was not calling builder.CreateModel() and passing it into the DbContext.

  • Anonymous
    July 16, 2010
    @ e36M3 Correct, the CTP is a preview of something we plan to RTM in the future. The RTM could be a service pack or full release of the framework. @simon & @noob.net Thanks! We’ve had this feedback from a few people, I’ve added in an explanation in the intro as well as spelling out the CTP acronym. @TheCloudlessSky You can set the initializer to be null and it will leave database creation in your hands:    Database.SetInitializer<ProductContext>(null); You can also switch off creation of the EdmMetadata table via a setting on ModelBuilder. (The EdmMetadata table is used internally to work out if the database schema matches the model)    public class ProductContext : DbContext    {        protected override void OnModelCreating(ModelBuilder modelBuilder)        {            modelBuilder.IncludeMetadataInDatabase = false;        }        ...    } You can map to an existing database if you make the appropriate ModelBuilder calls to specify how your classes map to tables, we’re seeing quite a few people do this successfully. @Roman Golubin Because the CTP builds on top of the existing EF API in a separate assembly there are places where you need to use types in the System.Data.Entity assembly. @TheCloudlessSky Regarding: modelBuilder.Entity<User>.HasMany(u => u.Profile).WithMany().HasConstraint((u, p) => u.DefaultProfileId == p.Id) HasConstraint is used when you include a foreign key property on your object, in the case of many:many there is no foreign key property since the relationships ends up as a join table in the database. This means HasConstraint is not valid on a many:many relationship, we will update the API so that HasConstraint is not available after calling HasMany().WithMany().

  • Anonymous
    July 16, 2010
    @Viktar This is great feedback, a number of people have been asking about smarter lazy loading recently. There are other items higher on the priority list (like enum support :) ) but being smarter about when and how we lazy load a collection is something we will look at.

  • Anonymous
    July 16, 2010
    @Mario & @Flippie Support for more data types in the core Entity Framework is something our team is working on for the next full framework release, spatial data in particular is a common ask and something we are working on at the moment. @ André EF already has built-in support for annotations in the model, Danny Simmons recently posted an example that shows customizing code generation based on these annotations; blogs.msdn.com/.../entityroots-an-ef-extensibility-exercise.aspx The Code First Fluent API in CTP4 currently doesn’t expose anyway to add annotations though.

  • Anonymous
    July 16, 2010
    Where can we read more about: how to work with existing DB, how not to wipe off your data from the database everytime you make a change to your classes and the database is recreated ? thanks.

  • Anonymous
    July 16, 2010
    ...or rather make "incremental" changes to the DB, i.e., just modify what changed on the model.

  • Anonymous
    July 17, 2010
    The comment has been removed

  • Anonymous
    July 17, 2010
    The comment has been removed

  • Anonymous
    July 18, 2010
    @Viktar: Try someComponent.SomeCollection.CreateSourceQuery().Take(5) to load just the five records you want.

  • Anonymous
    July 19, 2010
    Sorry, I've not readed Rowan Miller post explaining that:     modelBuilder.IncludeMetadataInDatabase = false; OK, all is correct!

  • Anonymous
    July 20, 2010
    Is there any support when doing code-first for implementing relationships as different types of collections (eg. as a Dictionary instead of a List)? If not, are you planning to add support for that in the future?

  • Anonymous
    July 21, 2010
    Will we get a objectcontext.RejectChanges method?

  • Anonymous
    July 22, 2010
    @Simon Robinson Code First (and EF in general) supports any collection type that implements ICollection<TEntity> (List<T>, ObservableCollection<T>, HashSet<T>, etc.) @RamanaB We don’t have plans to add RejectChanges for the next release, there are other features (enums etc.) that trumped it on the priority list It would be possible to implement RejectChanges on the current API surface by looking at the object state manager and reversing changes, although there are quite a few intricacies to take care of for a truly generic solution. This is something I’ll try and put together in a blog post in the near future.

  • Anonymous
    July 26, 2010
    @Rowan Miller, Thanks for the answer, indeed enum support and lazy collection filtering is something many people miss in EF :) @Matthew Wills, CreateSourceQuery() works on EntityCollection, I'm talking about filtering POCO collections

  • Anonymous
    July 28, 2010
    Is there an ability to define a map for a private field on a POCO class? I think that would give me more control over the design of my classes. For example I would like to map to a private field and provide a read-only property like so:        private IList<Book> _Books;        public virtual IEnumerable<Books> Books        {            get            {                return _Books                    .OrderBy(x => x.Author);            }        }

  • Anonymous
    July 30, 2010
    @Dan This isn't currently supported. We are looking at supporting mapping to protected properties in the future which would allow something similar if _Books was a protected property rather than a private field.  

  • Anonymous
    August 14, 2010
    I can't seem to manually open a connection using the code-first with existing database approach.  Works fine with the database first generated EntityCollection. Have we lost the ability to manually open connections in code-first?

  • Anonymous
    August 18, 2010
    The comment has been removed

  • Anonymous
    August 28, 2010
    @BDupree Once you have built a model the database connection should behave the same in EF regardless of Database/Model/Code First. If you are using DbContext then the connection is available via DbContext.Database.Connection. If you are experiencing issues then start up a thread on our pre-release forum with the code that isn’t working for you; social.msdn.microsoft.com/.../threads @Todd Morrison Thanks for the feedback!

  • Anonymous
    October 08, 2010
    Why would you need RelatedTo when DataAnnotations adds Associate that is used for RIA Services to tie together a Foreign Key? Is there additional information this is not giving you? And if so, why not make a Overload for Association to accommodate that instead of a new field. That way the Model object can work consistently with all of Microsofts Frameworks.

  • Anonymous
    October 20, 2010
    When can we expect the next version ?

  • Anonymous
    October 25, 2010
    The comment has been removed

  • Anonymous
    November 02, 2010
    Are there any plans to support PostgreSQL?

  • Anonymous
    November 16, 2010
    Does the CTP provide us with a way of changing a table structure at runtime. Adding and Removing properties on dynamic objects that will change the underlying table columns i.e DbSet<ExpandoObject>.  If not is this something that may see added?

  • Anonymous
    December 01, 2010
    Hi, anyone care to give us a heads up on when the next CTP (5 I guess) is roughly scheduled for? THanks

  • Anonymous
    December 02, 2010
    Please do not alphabetically sort the database columns by default. (Yes, this is what happens if you do the simplest code first approach - it ignores the layout of your types and decides it knows better and alphabetically sorts the columns in the db schema).

  • Anonymous
    December 02, 2010
    The comment has been removed

  • Anonymous
    December 04, 2010
    @Corey Gaudin The Association annotation does not allow you to specify the property on the other end of the relationship (i.e. Customer.Orders is the inverse of Order.Customer). At this stage we are a separate assembly that will ship before the next version of the .NET Framework which unfortunately means we can’t change the existing attributes. @Alexandre Brisebois & @nsgaga CTP5 will be released in the next week or so. @Inheritance question EF in general does not support this, it needs to be aware of all types in your model. @Donny V We don’t have any plans to write a PostrgreSQL provider but we have a public provider model that 3rd parties can implement. @James C This isn’t supported at the moment, we are starting to think about dynamic support but there are no firm plans around this at the moment. @Jack This will be fixed in CTP5, unfortunately there is no definitive way for us to find the order you actually wrote the properties in your class file but in CTP5 we will order Primary Key(s), Scalar Properties then Foreign Keys. Within those we will use the order that the reflection API gives us, which should (but is not guaranteed to be) the order you defined them.

  • Anonymous
    February 17, 2011
    @Rowan Miller Interesting thought that you cannot get the property ordering from the reflection API. Of course all of this will be fixed in C# 5 compiler whereby we can get all this type of information from the "compiler as a service" ... fingers crossed.

  • Anonymous
    February 17, 2011
    @Rowan Miller Dare I ask while I am here whether the great combined intellect of the EF team are ever going to get round to basic enum support (a la L2S from 4+ years ago...) It does kinda make EF a laughing stock in the circles I move

  • Anonymous
    June 03, 2013
    i really enjoy your sample projects