Freigeben über


EF and Visual Studio 2013 Preview

 


The information in this post is out of date.

EF6 RTM is now available.

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


 

The availability of Visual Studio 2013 Preview was announced today. This preview contains Entity Framework 6 Beta 1.

The EF6 Beta 1 runtime and EF Tools for VS2012 were released last month, this preview of Visual Studio contains the EF6 Beta 1 Tools for VS2013. The EF6 Beta 1 runtime is also included in a number of places – new ASP.NET projects and new models created with the EF Designer will use the EF6 runtime by default.

 

What’s New in EF6

Note: In some cases you may need to update your EF5 code to work with EF6, see Updating Applications to use EF6.

Tooling

Our focus with the tooling has been on adding EF6 support and enabling us to easily ship out-of-band between releases of Visual Studio.

The tooling itself does not include any new features, but most of the new runtime features can be used with models created in the EF Designer.

Runtime

The following features work for models created with Code First or the EF Designer:

  • Async Query and Save adds support for the task-based asynchronous patterns that were introduced in .NET 4.5. We've created a walkthrough and a feature specification for this feature.
  • Connection Resiliency enables automatic recovery from transient connection failures. The feature specification shows how to enable this feature and how to create your own retry policies.
  • Code-Based Configuration gives you the option of performing configuration – that was traditionally performed in a config file – in code. We've created an overview with some examples and a feature specification.
  • Dependency Resolution introduces support for the Service Locator pattern and we've factored out some pieces of functionality that can be replaced with custom implementations. We’ve created a feature specification and a list of services that can be injected.
  • Enums, Spatial and Better Performance on .NET 4.0 - By moving the core components that used to be in the .NET Framework into the EF NuGet package we are now able to offer enum support, spatial data types and the performance improvements from EF5 on .NET 4.0.
    Note: There is a temporary limitation in EF6 Beta 1 that prevents using the EF Designer to create EF6 models that target .NET 4.0.
  • DbContext can now be created with a DbConnection that is already opened which enables scenarios where it would be helpful if the connection could be open when creating the context (such as sharing a connection between components where you can not guarantee the state of the connection).
  • Default transaction isolation level is changed to READ_COMMITTED_SNAPSHOT for databases created using Code First, potentially allowing for more scalability and fewer deadlocks.
  • DbContext.Database.UseTransaction and DbContext.Database.BeginTransaction are new APIs that enable scenarios where you need to manage your own transactions.
  • Improved performance of Enumerable.Contains in LINQ queries.
  • Significantly improved warm up time (view generation) – especially for large models – as the result of a contributions from AlirezaHaghshenas and VSavenkov
  • Pluggable Pluralization & Singularization Service was contributed by UnaiZorrilla.
  • Improved Transaction Support updates the Entity Framework to provide support for a transaction external to the framework as well as improved ways of creating a transaction within the Framework. See this feature specification for details.
  • Entity and complex types can now be nested inside classes.
  • Custom implementations of Equals or GetHashCode on entity classes are now supported. See the feature specification for more details.
  • DbSet.AddRange/RemoveRange were contributed by UnaiZorrilla and provides an optimized way to add or remove multiple entities from a set.
  • DbChangeTracker.HasChanges was contributed by UnaiZorrilla and provides an easy and efficient way to see if there are any pending changes to be saved to the database.
  • SqlCeFunctions was contributed by ErikEJ and provides a SQL Compact equivalent to the SqlFunctions.

The following features apply to Code First only:

  • Custom Code First Conventions allow write your own conventions to help avoid repetitive configuration. We provide a simple API for lightweight conventions as well as some more complex building blocks to allow you to author more complicated conventions. We’ve created a walkthough and a feature specification for this feature.

  • Code First Mapping to Insert/Update/Delete Stored Procedures is now supported. We’ve created a feature specification for this feature.

  • Idempotent migrations scripts allow you to generate a SQL script that can upgrade a database at any version up to the latest version. The generated script includes logic to check the __MigrationsHistory table and only apply changes that haven't been previously applied. Use the following command to generate an idempotent script.

     Update-Database -Script -SourceMigration $InitialDatabase
    
  • Configurable Migrations History Table allows you to customize the definition of the migrations history table. This is particularly useful for database providers that require the appropriate data types etc. to be specified for the Migrations History table to work correctly. We’ve created a feature specification for this feature.

  • Multiple Contexts per Database removes the previous limitation of one Code First model per database when using Migrations or when Code First automatically created the database for you. We’ve created a feature specification for this feature.

  • DbModelBuilder.HasDefaultSchema is a new Code First API that allows the default database schema for a Code First model to be configured in one place. Previously the Code First default schema was hard-coded to "dbo" and the only way to configure the schema to which a table belonged was via the ToTable API.

  • DbModelBuilder.Configurations.AddFromAssembly method  was contributed by UnaiZorrilla. If you are using configuration classes with the Code First Fluent API, this method allows you to easily add all configuration classes defined in an assembly. 

  • Custom Migrations Operations were enabled by a contribution from iceclow and this blog post provides an example of using this new feature.

 

We Want Your Feedback

You can help us make EF6 a great release by providing feedback and suggestions. You can provide feedback by commenting on this post, commenting on the feature specifications linked below or starting a discussion on our CodePlex site.

 

Support

This 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. It is not intended or licensed for use in production. The APIs and functionality included in Beta 1 are likely to change as we polish the product ready for the final release of EF6.

If you need assistance using the new features, please post questions on Stack Overflow using the entity-framework tag.

Comments

  • Anonymous
    June 27, 2013
    The comment has been removed

  • Anonymous
    June 27, 2013
    @Jon - unfortunately it did not fit in the EF6 release. We are tracking it here: entityframework.codeplex.com/.../961. Feel free to upvote.

  • Anonymous
    June 27, 2013
    Thanks Pawel.

  • Anonymous
    July 03, 2013
    I've in production a Silverlight app that use EF4 as data layer through RiaServices in .NET 4.0. I don't know if RiaServices will ever support EF6 (imho, no). Let's suppose it does, what would be the best path: passing through EF5 or directly to EF6? Right now, of course, my app use "model first". If I would like to move to "code first", again, what would it be the best path: EF5 and than EF6 or EF6 directly? Thank you if you had the patience to read till now.

  • Anonymous
    July 08, 2013
    @Angelo Chiello - If you are able to wait until later this year for the RTM of EF6 then I would recommend moving directly to EF6. You may need to update your code a little to work with EF6 (entityframework.codeplex.com/wikipage), but if you are making the move to Code First then it probably makes sense to make all the changes in one go.

  • Anonymous
    July 08, 2013
    Thank you Rowan.. I'll surely wait for the RTM.

  • Anonymous
    July 09, 2013
    Does anyone have an idea when I'll be able to use all of my EF code on Windows Phone applications that target SQL Compact?  Right now, I have one code base for database access that uses EF on Windows 8 desktop with SQL Compact and another that uses the LINQ statements but also targets SQL compact.  I really would like to have one code base using EF that I can compile for either Windows Phone or Windows 8.  Am I asking for the impossible??

  • Anonymous
    July 11, 2013
    It seems, that link to future specification of improved transaction support is broken. Right link: entityframework.codeplex.com/wikipage

  • Anonymous
    July 15, 2013
    @Viktor Lova - Thank you, I've fixed the link.

  • Anonymous
    July 18, 2013
    One thing that I've been hoping for with regard to the new async support is that it would be great if say a user of an ASP.NET web application makes a page request that results in an expensive database query and then they click the browser stop button or navigate to another page, that it would cancel the database query as well. I know it's wishful thinking, but, it would be great if it worked. Another thing I was wondering is if lazy loading of properties is planned anytime soon? It would be useful for example, if say you have an NVARCHAR(MAX) column that has large data in it and you want to query against the table, but, get all fields except that one, or at least have it lazy loaded. It would be nice if there was an Exclude() method similar to Include(). Normally, I would just do a projection in this case and only select the columns that I want. However, one time when it would be nice to not do a projection is if you are using the new strongly typed data binding in ASP.NET 4.5 where to a certain extent, it wants full entities, unless you define a view model-like class for storing the projection results rather than using an anonymous type.

  • Anonymous
    July 25, 2013
    There's an Edit Enum Type modal window accessible from the EDMX Model Browser. Please make the grid more flexible e.g. add ability to insert values in the middle in stead of having to do the whole list over and again when a new value is added.

  • Anonymous
    July 26, 2013
    @Jon - ASP.NET has a ClientDisconnectedToken (a CancellationToken) that you can pass through to async calls (there is an overload of all the EF async methods that takes a CancellationToken) - msdn.microsoft.com/.../system.web.httpresponse.clientdisconnectedtoken.aspx. Lazy loading properties is still on the backlog and we don't have any definite plans for a timeline etc. (sorry I can't give you anything more concrete than that... but that's all we know at the moment).

  • Anonymous
    July 26, 2013
    @Dec  - Feel free to open a feature request and our team will triage it - entityframework.codeplex.com/.../Create

  • Anonymous
    July 26, 2013
    @Frustrated EF Developer - Difficult, but not impossible :). It's something we are looking into, but we haven't made any definite plans yet. Here is a work item you can vote on and track - entityframework.codeplex.com/.../403.

  • Anonymous
    August 13, 2013
    The comment has been removed