共用方式為


EF6.1.0 RTM Available

Since the release of EF6 our team has been working on the EF6.1 release. This is our next release that includes new features.

 

What’s in EF6.1

EF6.1 adds the following new features:

  • Tooling consolidation provides a consistent way to create a new EF model. This feature extends the ADO.NET Entity Data Model wizard to support creating Code First models, including reverse engineering from an existing database. These features were previously available in Beta quality in the EF Power Tools.
  • Handling of transaction commit failures provides the CommitFailureHandler which makes use of the newly introduced ability to intercept transaction operations. The CommitFailureHandler allows automatic recovery from connection failures whilst committing a transaction.
  • IndexAttribute allows indexes to be specified by placing an [Index] attribute on a property (or properties) in your Code First model. Code First will then create a corresponding index in the database.
  • The public mapping API provides access to the information EF has on how properties and types are mapped to columns and tables in the database. In past releases this API was internal.
  • Ability to configure interceptors via the App/Web.config file allows interceptors to be added without recompiling the application.
    • System.Data.Entity.Infrastructure.Interception.DatabaseLogger is a new interceptor that makes it easy to log all database operations to a file. In combination with the previous feature, this allows you to easily switch on logging of database operations for a deployed application, without the need to recompile. Migrations model change detection has been improved so that scaffolded migrations are more accurate; performance of the change detection process has also been enhanced.
  • Performance improvements including reduced database operations during initialization, optimizations for null equality comparison in LINQ queries, faster view generation (model creation) in more scenarios, and more efficient materialization of tracked entities with multiple associations.
  • Support for .ToString, String.Concat and enum HasFlags in LINQ Queries.
  • System.Data.Entity.Infrastructure.Interception.IDbTransactionInterceptor is a new interceptor that allows components to receive notifications when Entity Framework initiates operations on a transaction.

 

Where do I get EF6.1?

The runtime is available on NuGet. If you are using Code First then there is no need to install the tooling. Follow the instructions on our Get It page for installing the latest version of Entity Framework runtime.

The tooling for Visual Studio 2012 and Visual Studio 2013 is available on the Microsoft Download Center. You only need to install the tooling if you want to use Model First or Database First.

 

What’s new since EF6.1 Beta 1?

Since the Beta 1 of EF6.1 we’ve just been fixing bugs and tidying up the new features. There are no new features in the RTM since Beta 1.

 

Thank you to our contributors

We’d like to say thank you to folks from the community who contributed features, bug fixes, and other changes to the 6.1 release - RogerAlsing, ErikEJ, and mikecole.

In particular, we’d like to call out the following contributions:

  • Support for String.Concat and .ToString in LINQ queries (RogerAlsing)
  • Support for enum HasFlags method in LINQ queries (RogerAlsing)
  • Entity SQL canonical function support for SQL Server Compact (ErikEJ)
  • Fix for a bug that was affecting EF running under Mono (ErikEJ)

Comments

  • Anonymous
    March 17, 2014
    Fantastic news guys. EF is super powerful now! Any roadmap for vNext?

  • Anonymous
    March 17, 2014
    Congratulations team -- I really mean it!  Between the public mapping API and a few specific bugs fixed, this is the release I've been looking forward to ever since I started using EF with the 4.1 previews. (No more reflection, yay!) I was wondering about the transaction commit failure feature.  Specifically, is there a published SQL script separate from the migrations mechanism it seems to currently use?  We don't allow our application accounts to make schema changes since there are multiple apps that connect to the same database. I just let the migration run against a local database, scripted the table and added it to the SSDT project we use to manage the database schema.  Is this a bad idea?  How likely is it to change in future releases?

  • Anonymous
    March 17, 2014
    I'm wondering, are there any improvements to Database First tooling?

  • Anonymous
    March 17, 2014
    Can I set up indexes using Fluent API?

  • Anonymous
    March 17, 2014
    I also contributed a new provider for SQL Server Compact 3.5 (based on the 4.0 provider) www.nuget.org/.../EntityFramework.SqlServerCompact.Legacy - it can also be used with the new EF Tools if you install my SQL Server Compact Toolbox add-in

  • Anonymous
    March 17, 2014
    Great news. .ToString() => Yes :)

  • Anonymous
    March 17, 2014
    Can we now get the PDBs from a Symbol server?

  • Anonymous
    March 17, 2014
    The comment has been removed

  • Anonymous
    March 17, 2014
    Fantastic!  Does this release support .NET 3.5/4.0 or does it require .NET 4.5? I'm really hoping that something like moozzyk's work on Code First support of TVF's / stored procedures (see Store Functions for Entity Framework Code First here:  codefirstfunctions.codeplex.com) will make it into EF vNext    :-)     That's my favorite UserVoice feature request (data.uservoice.com/.../1607971-code-first-support-for-stored-procedures)

  • Anonymous
    March 17, 2014
    Nice Job. Are there any plans to implement mapping to Interfaces in the next release?

  • Anonymous
    March 18, 2014
    @David McClelland  - Now that EF6.1 is shipped I am planning to ship the Store Functions for Entity Framework Code First (codefirstfunctions.codeplex.com) as a NuGet package. Stay tuned.

  • Anonymous
    March 18, 2014
    It's great to see things quickly moving forward! Is there any more info about the faster view generation (model creation)?  This has been a major pain point for us, even a small data context with 5 models can take 10 seconds to initialize after each build.  That's a long time to wait before you can see your app or run integration tests. Ideally all the work could happen when the context/model/mapping changes rather than at run-time after each build.  We've tried using pre-compiled views but that doesn't seem to help much, so maybe it's some other aspect of initialization.  It would be great to get this down to the same sub-second ballpark as Linq to Sql, our code that relies on EF is painfully slow to initialize in comparison.

  • Anonymous
    March 18, 2014
    @shawn: If pre-generating the views doesn't make any difference in your application start up performance, then view generation is most likely not the issue you are seeing. There is other work that might be taking the 5 seconds, e.g. if you are using Code First and it is relatively large model then just building the model may take some time. Also, in EF6 it is very common that loading the EF assembly and having the JIT compiler translate its IL into native code will take between 1 (for x86) and 3 (for x64) seconds. There is help on how to address that here: msdn.microsoft.com/.../dn582034. HTH, Diego

  • Anonymous
    March 18, 2014
    The comment has been removed

  • Anonymous
    March 18, 2014
    I'm wondering if any thought has been given to adding support for full-text searches in SQL Server through EF? For example, maybe add something to the SqlFunctions class? Even if it was SQL Server specific, it would be nice to have a way of filtering using full-text search criteria and have it return entities.

  • Anonymous
    March 19, 2014
    @Jon: Regarding the ArgumentException thrown from MetadataCollection, could you please file a bug at entityframework.codeplex.com/.../Create and attach a repro to it so that we can investigate? For what it is worth, in the past we have seen cases similar to this and the reason was that a column name put together by EF conflicted with a column name that already existed in the database schema. The general workaround is to configure one of the column names explicitly, e.g. using the HasColumnName API.

  • Anonymous
    March 19, 2014
    This is indeed a great update with much needed feature. I suggest improving the index functionality a bit by allowing inclusion of non-key columns. It would be great to have this.

  • Anonymous
    March 21, 2014
    I'm confused about 6.1.  I thought we would see these controls mentioned in this post: blogs.msdn.com/.../preview-of-dynamic-data-provider-and-entitydatasource-control-for-ef6.aspx "What’s in this preview •DynamicData provider for Entity Framework 6 •EntityDataSource control for Entity Framework 6" I'm interested in seeing the EntityDataSource control return but I didn't notice it in the list of features for 6.1 - can you clarify?  Thanks.

  • Anonymous
    March 21, 2014
    Thanks Diego. The strange thing is that I did a search for that column name through the entire model and there is only one column with that name. I will try to create a slimmed down version of my model and see if it has the problem. And try to submit a bug report with that.

  • Anonymous
    March 21, 2014
    @daveharney: EntityDataSource for EF6 and the DynamicData provider for EF6 are separate packages from the EF runtime and tooling. We actually shipped the "RTM" version of them a few days ago, but we only announced it in the .NET Web Development blog: blogs.msdn.com/.../announcing-the-release-of-dynamic-data-provider-and-entitydatasource-control-for-entity-framework-6.aspx.

  • Anonymous
    March 21, 2014
    EF6.1 has serious issue not found on 6.0.2. I get Out of Memory or Timeout when I use the following line, leaving my website and server in a frozen state.        fetchStrategy          .Include(l => l.HorseAd)          .Include(l => l.HorseAd.Advertiser)          .Include(l => l.HorseAd.Advertiser.Listings)          .Include(l => l.HorseAd.HorseCategories)          .Include(l => l.HorseAd.HorseDisciplines)          .Include(l => l.HorseboxAd)          .Include(l => l.HorseboxAd.Advertiser)          .Include(l => l.HorseboxAd.Advertiser.Listings); Removing last include fixes issue. The bug is probably related to the number of includes.

  • Anonymous
    March 22, 2014
    Looks like String.Concat(IEnumerable<string> arg) is not translated to the SQL: foreach (var result in db.CarTypeGroups.Select(g => new { groupname = g.Name, cartypes = String.Concat(g.CarTypes.Select(ct => ct.Name)) }) ) {    Console.WriteLine("{0} - {1}", result.groupname, result.cartypes);     } Additional information: LINQ to Entities does not recognize the method 'System.String Concat(System.Collections.Generic.IEnumerable`1[System.String])' method, and this method cannot be translated into a store expression. Only db.CarTypeGroups.Select(g => String.Concat("123", "456")) works. But in this case we can simply do "123" + "456"...

  • Anonymous
    March 22, 2014
    Hi Diego, Thanks for the link.  I tried it without success - left a message over there.  Maybe I'm dense, but it doesn't seem like it should be this difficult.

  • Anonymous
    March 23, 2014
    I find it's really a bug, below is my total code: using System; using System.Data.Entity; namespace ConsoleApplication1 {    class Program    {        static void Main(string[] args)        {            using (MyContext context = new MyContext())            {                bool b = context.Database.CreateIfNotExists();                MyClassToA toA = new MyClassToA() { A = "A" };                context.MyClasses.Add(toA);                MyClassToB toB = new MyClassToB() { B = "B" };                context.MyClasses.Add(toB);                context.SaveChanges();            }        }    }    public abstract class MyClass    {        public MyClass()        {            this.Id = Guid.NewGuid();        }        public Guid Id { get; private set; }        public string Name { get; set; }    }    public class MyClassToA : MyClass    {        public string A { get; set; }    }    public class MyClassToB : MyClass    {        public string B { get; set; }    }    public sealed class MyContext : DbContext    {        public DbSet<MyClass> MyClasses { get; set; }        protected override void OnModelCreating(DbModelBuilder modelBuilder)        {            base.OnModelCreating(modelBuilder);            modelBuilder.Entity<MyClass>().Map<MyClassToA>(m => m.Requires("Discriminator").HasValue("A").IsRequired());            modelBuilder.Entity<MyClass>().Map<MyClassToB>(m => m.Requires("Discriminator").HasValue("B").IsRequired());        }    } } When running to SaveChanges(), an exception throw, but it's OK when using EF6.0.2 {"rn(6,10) : error 3032: Problem in mapping fragments starting at lines 6, 12:EntityTypes ConsoleApplication1.MyClassToA, ConsoleApplication1.MyClassToB, ConsoleApplication1.MyClassToC are being mapped to the same rows in table MyClass. Mapping conditions can be used to distinguish the rows that these types are mapped to.rn"}

  • Anonymous
    March 24, 2014
    @Andrew Veresov The string.Concat overload that takes IEnumerable is not supported. If it was it would have to be translated to a query that concatenates many rows into a scalar string value. While this probably could be done (a quick search shows that it does not seem to be very straightforward) I don't know how useful it would be on the server side - e.g. it could be used in a WHERE clause but a column you would compare against would have to have a value that was created using a similar concatenate logic, it could be used for grouping but I don't know how effective it would be. In your case you can do the concat on the client by enforcing query evaluation the query before passing to string.Concat e.g.: String.Concat(g.CarTypes.Select(ct => ct.Name).ToList()). Note that g => String.Concat("123", "456") is not very useful because you know the values (they are const) and you could just hardcode the value. I believe this is what happened to "123" + "456" if it worked for you in 6.0.2 - the CSharp compiler optimized it just to a constant literal but if you had something like this: var s1 = "123"; g => string.Concat(s1 + "456"); g=> s1 + "456"; wouldn't have worked. Also note that if you use entity properties they will be translated to columns and the concat will happen on the server side. Pawel

  • Anonymous
    March 24, 2014
    @Jon: I think the following bug captures the issue you are seeing. It only affects entities that have 10 or more key members when a column name is specified that is different from the default: entityframework.codeplex.com/.../2169

  • Anonymous
    March 24, 2014
    Do we have to NGEN assemblies again after updating from 6.02 to 6.1 ?

  • Anonymous
    March 24, 2014
    @J. Portelli: yes, native images created by ngen only apply to individual builds of each assembly, e.g. if you recompile an assembly even without making code changes, old native images won't be picked up for the new build.

  • Anonymous
    March 25, 2014
    I'm not sure if this problem is new to 6.1, or if it was also present in 6.0, but, I just upgraded a project from 5.0 to 6.1 and I'm running into the following error LINQ to Entities does not recognize the method 'System.Nullable1[System.Int32] DiffHours(System.Nullable1[System.DateTime], System.Nullable`1[System.DateTime])' method, and this method cannot be translated into a store expression. when attempting to run the following query.            RadPivotGrid1.DataSource = (from t in q                                        where t.ReceiveTime != null && t.LendingLibraryCode != null                                        select new                                        {                                            t.Id,                                            BorrowingLibrary = t.BorrowingLibraryName,                                            UBorrowRequestTimeToReceiveTime = EntityFunctions.DiffHours(t.UBorrowRequestTime, t.ReceiveTime) / 24m,                                            UBorrowRequestTime = EntityFunctions.CreateDateTime(t.UBorrowRequestTime.Value.Year, t.UBorrowRequestTime.Value.Month, 1, 0, 0, 0)                                        }).ToList(); It appears that something with EntityFunctions.DiffHours() has changed in EF 6 from 5.

  • Anonymous
    March 25, 2014
    Never mind, it looks like I just needed to remove the System.Data.Entity.dll reference from my project and rename EntityFunctions to DbFunctions.

  • Anonymous
    March 30, 2014
    The comment has been removed

  • Anonymous
    March 31, 2014
    When POCOs are generated by the Code-First with existing database wizard, the resulting class files are not marked as auto-generated.  This causes code analysis errors because some properties are marked as virtual. Code analysis/StyleCop generally ignores files that are marked as auto-generated.  This is a handy thing.  But it has to be given a hint that they are auto-generated. It seems that in prior releases of the EF Power Tools, there was a Customize Reverse Engineer Templates option available from the context menu of a project.  (I never used it, I'm just going on documentation I've found on the internet). Additionally, there is no .tt file to be found related to EF after having created my ado.net entity framework Entity Data Model (Code First from database).

  1.  Is this tool supposed to be available in Entity Framework 6.1 with Power Tools installed?
  2.  If so, where is it?
  3.  If not, what is the proposed solution (apart from manually editing each of the generated files) for adding the kind of attributes/comments generally provided in auto-generated files.  For example:  [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
  • Anonymous
    April 04, 2014
    The Code First generation from An Existing Database seems to be completely different in 6.1. Am I right in thinking that the edmx & tt files are now gone (which is a good thing in my opinion) ?

  • Anonymous
    April 07, 2014
    @CPJ - EDMX and tt is still there if you want to use the EF Designer. Code First has never used these artifacts (by it's nature it is just code). In 6.1 we just combined the EF Designer and Code First into the same 'create model' wizard (previously the Code First wizard was separate and shipped as part of the EF Power Tools).

  • Anonymous
    April 07, 2014
    @Clement – Our team is currently looking into providing EF on other platforms (Windows Phone, Windows Store Apps, etc.). You can read more about that here - entityframework.codeplex.com/wikipage. In addition, we’re also working on the 6.1.1 release which will include bug fixes and some small features that were contributed by the community.

  • Anonymous
    April 07, 2014
    @James S – We don’t have the script published anywhere, your approach sounds fine. It may change in the future, but not super likely. Provided you test your application when you upgrade, you should find any issues pretty quickly.

  • Anonymous
    April 07, 2014
    @Konstantin Tarkus – 6.1 includes a few bug fixes for the existing designer, but nothing major.

  • Anonymous
    April 07, 2014
    @Andrei – Details on configuring indexes from the Fluent API are here - msdn.com/.../jj591617.

  • Anonymous
    April 07, 2014
    @Andre.Ziegler – We were blocked uploading a symbol package by a technical issue with Symbol Source. Someone on our team is looking into it again now.

  • Anonymous
    April 07, 2014
    @中华鹰 – This looks like a bug we are already tracking to fix in 6.1.1 - entityframework.codeplex.com/.../2176.

  • Anonymous
    April 07, 2014
    @David McClelland – This release will run on .NET 4 onwards. You will need 4.5 to use the async support.

  • Anonymous
    April 07, 2014
    @Ralf – We’re not planning to support interfaces in the upcoming releases – unless someone contributes it :).

  • Anonymous
    April 07, 2014
    @Jon – Full text search isn’t at the top of the backlog, but it is something we see folks asking for a bit. The best solution at the moment is a TVF, sproc, or executing raw SQL.

  • Anonymous
    April 07, 2014
    @Sherif Elmetainy – You can create indexes on non-key columns already. You can’t use them as the target of a foreign key though – even if they are unique.

  • Anonymous
    April 07, 2014
    @ robnorthen – If you haven’t already, can you log an issue on CodePlex with details of the issue you are hitting - entityframework.codeplex.com/.../Create. Be sure to include code that reproduces the issue.

  • Anonymous
    April 07, 2014
    @Jon – Installing the EF6 NuGet package should have removed the reference to System.Data.Entity.dll, but given that didn’t happen, your change is correct.

  • Anonymous
    April 07, 2014
    The comment has been removed

  • Anonymous
    April 27, 2014
    LastOrDefault of DateTime is not working. FirstOrDefault of DataTime works fine in EF 6.1 or higher. Something like the following will not work: x.OrderDetails.Select(f => f.OrderDate).LastOrDefault() Causes the following error. LINQ to Entities does not recognize the method 'System.Nullable1[System.DateTime] LastOrDefault[Nullable1](System.Collections.Generic.IEnumerable1[System.Nullable1[System.DateTime]])' method, and this method cannot be translated into a store expression.

  • Anonymous
    April 27, 2014
    Also, it fails on String with LastOrDefault. I am guessing that any type will fail with LINQ to Entity when using LastOrDefault

  • Anonymous
    April 27, 2014
    Oh... looks like LastOrDefault is not supported. For future reference. msdn.microsoft.com/.../bb738550.aspx

  • Anonymous
    April 28, 2014
    @ImGonaRot I think I ran into that one myself awhile ago. I think what I did was order the results in descending order and then use FirstOrDefault() on that.

  • Anonymous
    April 29, 2014
    @ImGonaRot & @Jon - Descending sort and FirstOrDefault is the approach we would recommend too. The limitation is just because EF doesn't know how to convert LastOrDefault in SQL that can be run in the database.

  • Anonymous
    June 26, 2014
    I grabbed 6.1.1 hoping that it would improve the initialization of EF in my database first model.  When I restart my data service the first time I hit EF it takes about 10 seconds to "warm up".  All subsequent calls are sub-second as I would expect given the simplicity of the sql statement that is ultimately run.

  • Anonymous
    June 26, 2014
    @Mike B - Are you able to provide a model that demonstrates the issue? If so, open an issue and we can dig into it and see what the bottle neck is - entityframework.codeplex.com/.../Create.

  • Anonymous
    April 06, 2015
    hi, can you please provide an example of the .ToString in the LINQ queries (IQueryable)? I don't see it work, still get the error "LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method"

  • Anonymous
    April 06, 2015
    hello, still get the error "LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method" with the EF 6.1.2.

  • Anonymous
    May 19, 2015
    I too am having trouble getting .ToString() to work. I still get the old error message.

  • Anonymous
    June 03, 2015
    The comment has been removed

  • Anonymous
    June 03, 2015
    I was talking about  CommitFailureHandler in my previous comment, as for the rest of EF6 we have had a great success story at scale.

  • Anonymous
    June 09, 2015
    I have Nservicebus for handling messages but my entities save successfully in database but method committed  IDbTransactionInterceptor  not calling from nservicebus , it's a bug? or I missed some configuration? but it's works propery in regular project

  • Anonymous
    November 18, 2015
    @khoailang, @John Doe & @mikesigs – Can you open an issue on our CodePlex project with your LINQ query, so that we can see what is going wrong. entityframework.codeplex.com

  • Anonymous
    November 18, 2015
    @DalSoft – Feel free to open an issue on our project with details of the bottleneck you saw. We may be able to improve the implementatio. entityframework.codeplex.com

  • Anonymous
    November 18, 2015
    @amir bidava – We probably need to look at your code to see why it is not firing, open up an issue and include your code entityframework.codeplex.com.