EF Feature CTP5 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.
The latest Entity Framework Feature Community Technology Preview (CTP5) is now available for download. This CTP includes updates to the Code First feature and the simplified API surface (DbContext).
Getting Started
We’ve created a couple of posts to get you started with CTP5, we’ll also be providing more detailed posts that dive down into interesting areas in the coming weeks.
Support
CTP5 is a preview of features that will be available in future releases and is designed to allow you to provide feedback on the design of these features. CTP5 is not intended or licensed for use in production. If you need assistance with CTP5 we have an Entity Framework Pre-Release Forum.
Road Map
CTP5 will be our final preview of Code First and the simplified API surface (DbContext) before we offer a full supported production ready release in Q1 of 2011.
Known Issues
CTP5 includes some significant internal refactoring in preparation for some features we intend to support in the future, we are still in the process of stabilizing the quality after this refactoring. We decided to release before we finished this stabilization to get CTP5 in your hands as soon as possible and give ample time to incorporate feedback before we RTM.
In particular there are some specific known issues in CTP5;
- Table & Column Mapping in the Fluent API
We have done some work to make the mapping of classes/properties to tables/columns simpler and more intuitive in CTP5. We are still working to improve the quality of this new work, particularly around the mapping of inheritance hierarchies. - Pluggable Conventions
CTP5 includes a very early preview of this feature that is not complete and has not been extensively tested. - The new Validation feature is currently only supported when using Code First
What’s Changed?
There are a number of changes to existing features since CTP4, so you may be wondering where to find things:
- New Assembly Name
Our assembly name has changed to EntityFramework.dll - Better Code First to Existing Database Support
CTP5 removes the need to switch off Database Initializers when working with existing databases with Code First. If you map to an existing database that Code First did not create then it will just ‘trust you’ - DbContext.ObjectContext has moved
Rather than being a protected member we have made the underlying ObjectContext available via an explicitly implemented interface, this allows external components to make use of the underlying context. Getting the context now looks like; ((IObjectContextAdapter)myContext).ObjectContext - Excluding EdmMetadata Table
If Code First is generating your database and you wish to exclude the EdmMetadata table, this is now done by removing a convention (note that you do no longer need to do this when mapping to an existing database).
public class MyContext : DbContext { ... protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); } }
- Class Changes
CTP4 Name | CTP5 Name |
Database | System.Data.Entity.Database.DbDatabase |
RecreateDatabaseIfModelChanges | System.Data.Entity.Database.DropCreateDatabaseIfModelChanges |
AlwaysRecreateDatabase | System.Data.Entity.Database.DropCreateDatabaseAlways |
CreateDatabaseIfNotExists | System.Data.Entity.Database.CreateDatabaseIfNotExists |
SqlConnectionFactory | System.Data.Entity.Database.SqlConnectionFactory |
SqlCeConnectionFactory | System.Data.Entity.Database.SqlCeConnectionFactory |
What’s New?
New additions since CTP4 include;
DbContext
T4 Templates for using DbContext/DbSet with Model First & Database First
Validation of objects on save
Validation is based on the use of Data Annotations and currently only supported in Code First
Change Tracker API
Allows you to access information and operations applicable to objects that are tracked by a DbContext
- Original, Current & Store Values
- State (i.e. Added, Unchanged, Modified, Deleted)
- Explicit Load (i.e. load the contents of a navigation property from the database)
DbSet.Local exposes an ObservableCollection representing the local contents of the DbSet
This is particularly useful when performing databinding in WPF or WinForms
Support for No-Tracking Queries via the AsNoTracking extension method on IQueryable<T>
DbContext Configuration
Allows the following options to be configured for a DbContext instance;(Note: All of these are On by default)
- Lazy Loading
- Validate On Save
- Auto Detect Changes
Raw SQL Query/Command
Allows raw SQL queries and commands to be executed via the SqlQuery & SqlCommand methods on DbContext.Database. The results can optionally be materialized into object instances that are tracked by the DbContext via the SqlQuery method on DbSet.
Improved concurrency conflict resolution
CTP5 provides better exception messages that allow access to the affected object instance and the ability to resolve the conflict using current, original and database values
Code First
Full data annotation support
The full list of data annotations supported in CTP5 is;
KeyAttribute
StringLengthAttribute
MaxLengthAttribute
ConcurrencyCheckAttribute
RequiredAttribute
TimestampAttribute
ComplexTypeAttribute
ColumnAttribute
Placed on a property to specify the column name, ordinal & data type
TableAttribute
Placed on a class to specify the table name and schema
InversePropertyAttribute
Placed on a navigation property to specify the property that represents the other end of a relationship
ForeignKeyAttribute
Placed on a navigation property to specify the property that represents the foreign key of the relationship
DatabaseGeneratedAttribute
Placed on a property to specify how the database generates a value for the property (Identity, Computed or None)
NotMappedAttribute
Placed on a property or class to exclude it from the database
Fluent API Improvements
- Simplified table and column mapping
- Ability to ignore classes & properties
Pluggable Conventions
Based on the large amount of feedback requesting this feature we have included an early preview in CTP5. We still have some work to do on this feature but we wanted to give you the chance to provide feedback before we RTM. We’ll provide more details on this feature in the coming weeks.
Please keep the feedback coming!
ADO.NET Entity Framework Team