We are very pleased to announce the release of Entity Framework 5. EF5 is available as the Entity Framework NuGet package and is also included in Visual Studio 2012.
What’s New in EF5
EF 5 includes a number of new features and bug fixes to the EF4.3 release. Most of the new features are only available in applications targeting .NET 4.5, see the Compatibility section for more details.
- Enum support allows you to have enum properties in your entity classes.
- Spatial data types can now be exposed in your model using the DbGeography and DbGeometry types.
- The Performance enhancements that we recently blogged about.
- Code First will now detect if you have LocalDb or SQL Express available for creating new databases. Visual Studio 2012 includes LocalDb, whereas Visual Studio 2010 includes SQL Express.
- Code First will add tables to existing database if the target database doesn’t contain any of the tables from the model.
The EF Designer in Visual Studio 2012 also has some new features:
- DbContext code generation for new models means that any new models created using the EF Designer will generate a derived DbContext and POCO classes by default. You can always revert to ObjectContext code generation if needed. Existing models will not automatically change to DbContext code generation.
- Multiple-diagrams per model allows you to have several diagrams that visualize subsections of your overall model. Shapes on the design surface can also have coloring applied.
- Table-Valued functions in an existing database can now be added to your model.
- Batch import of stored procedures allows multiple stored procedures to be added to the model during model creation.
Get Started @ msdn.com/data/ef
The updated EF MSDN site includes a bunch of walkthroughs and videos to get you started with Entity Framework, including the new features in EF5.
What Changed Since the Release Candidate
You can see a list of bugs that we fixed since the EF5 RC on the EF CodePlex site.
The most notable change since RC is that new models created using the EF Designer in Visual Studio 2012 will now generate a derived DbContext and POCO classes by default. You can always revert to ObjectContext code generation if needed.
Compatibility
This version of the NuGet package is fully compatible with Visual Studio 2010 and Visual Studio 2012 and can be used for applications targeting .NET 4.0 and 4.5.
Some features are only available when writing an application that targets .NET 4.5. This includes enum support, spatial data types, table-valued functions and the performance improvements.
Need Help
Head to the EF MSDN site to find out how to get help with Entity Framework.
Entity Framework Team
I thought you guys are using SemVer. Is the assembly version 4.4 or 5.0?
@Jarrett Vance – We are following SemVer, this is EF 5.0.0. One small implementation detail is that the EF5 assembly for .NET 4.0 has an assembly version of 4.4 (to avoid the CLR thinking that the .NET 4.0 and .NET 4.5 assemblies for EF5 are the same assembly). If you look at the file version or informational version of either assembly it is 5.0.0.
Thanks, guys! Are providers for SQL Server Compact also published?
Is the Self-Tracking Entities Template for EF 5 ready?
@Mark – We're just sorting out the license for the STE templates. We expect to have them up later this week.
After updating a project to target .NET 4.5 and reference EF 5, NotMapped stopped working as expected when NotMapped is applied to a property in a base class that is defined in a different assembly. Specifics are at stackoverflow.com/…/141172
Is Entity Framework Power Tools Beta 2 compatible with VS2012? Can't seem to install it.
Having trouble getting any information on if or when Azure will support .NET 4.5 and therefore EF 5. Does anyone know?
Cool do you have any plans to support mono?
@Eric J. – We’ll follow up on the Stack Overflow thread.
@Patrick Tran – Yes, the Power Tools work with VS2012. If you’re having issues then startup a Stack Overflow thread with details.
@Mark Broomfield – I know it’s coming but I don’t have any idea on the timeline sorry.
@Volodymyr – Yep… it’s there in the latest release – tirania.org/…/Aug-13.html. One cool outcome from our open source move 🙂
@Andrei Mazoulnitsyn – Yes, the EntityFramework.SqlServerCompact NuGet package will work with EF5.
When using the designer, I think the properties on the generated classes should be virtual. Otherwise, you run into performance issues if you have a lot of objects in the context (I.e. it won't use change tracking proxies). For example, in a program that batch loads enttities. This wasn't an issue when using ObjectContext.
@Mark – STE templates are on VS Gallery now – visualstudiogallery.msdn.microsoft.com/…/search
Nice. Any news about the release of EF 6 beta that will support TVF and SPROC for code first?
@Jon – Unless you are dealing with large data sets the performance difference is usually pretty minimal and change tracking proxies have some nuances that can be confusing if you don't understand exactly what is going on. That's why we decided to make the default just lazy loading proxies.
In Visual Studio 2012 the code generation templates are just there nested under the edmx file so you can open the tt file and add the virtual keyword to the line that generates properties.
@Khaled – Not yet, we wanted to get EF5 shipped before we starting getting an EF6 beta release together. I'm not sure if the first beta will include sproc mappings in Code First because we haven't started implementing it yet.
Great work guys! Question: Why does enum support require VS 2012 / 4.5 Framework targeting? What is the technical reason behind this?
@Aaron – supporting enums required changes to the core EF library which is part of the .NET Framework. .NET Framework 4.5 contains a new version of System.Data.Entity.dll that has these changes whereas version shipped with .NET Framework 4 does not. Hence the requirement of .NET Framework 4.5
Great news finally it is officially released. I also found EF 5 STE generator on Visual Studio Gallery. so here is my question. will we be able to use EF 5 and Self Tracking Entities while still using VS 2010 and targeting NET 4? as far as I know there are some real performance gains in EF 5 so it would be really good to see blog post explaining ho to use EF 5 with STE and VS 2010 targeting to NET 4.
@Aaron King – In addition to what Pawel already said, in the next release of EF we’ll be moving those last few components out into the NuGet package. This means we can implement new features, such as enums, without having to require a new version of .NET. It was purely technical and time constraints that prevented us doing this in EF5.
@TaicoDev – The STE templates are included in the box with Visual Studio 2010, the ones on VS Gallery are exactly the same as we haven’t moved STEs over to the new DbContext API – they still use ObjectContext. The performance improvements are only available in application targeting .NET 4.5 – see the previous posts from Pawel and myself for more info on why that is. The bottom line is that if you are targeting .NET 4 in VS2010 then you should keep using the templates that are provided in the box.
Don't know if it is appropriate to post it here, but would you please have a look of this bug?
connect.microsoft.com/…/entity-framework-designer-ignores-nullability-specified-manually-when-update-model-from-database
OK i understand now, but does this mean I still have to use EF 4? and can not move to EF5
@TaicoDev – Correct, you will need to stay on EF4 in this scenario.
@deerchao – We will look at your Connect bug and reply to it.
Please give option for EF 5 installer or zip. Due to proxy issue I cannot install through NuGet.
@Ashraf – If you log into http://nuget.org you can download the EF NuGet package – just go to the EF package page and there is a Download link. You can then either host a local feed docs.nuget.org/…/hosting-your-own-nuget-feeds, or the .nupkg file you get is just a zip, so you can rename it to a .zip and get the assembly.
Note that if you extract the assembly you will lose the Package Manager Console commands, so we would recommend setting up a local feed.
Thanks, One question: Other ORMs, (those not included in .Net class libraries) can be used in the project as a dll. Why we can't do the same with EF? why should we wait till the next .Net release? Or need to increase the .Net version requirement of the app?
@Alireza Haghshenas – We agree! The new features require .NET 4.5 this time around because there are still some parts of EF in the .NET Framework. But in EF6 we are moving the last components into the NuGet package. In fact, some of the features that require .NET 4.5 in EF5 will start working on .NET 4 in EF6. Technical challenges and time constraints prevented us making these changes in EF5.
When is the EntityObject T4 template going to be released to the VS Gallery? Becoming frustrated…
stackoverflow.com/…/entity-framework-5-0-entityobject-generator-not-available-in-visual-studio-2012
It seems EF5 likes to put dbo. into table names when creating key constraints.
I've got a migration that's not being handled well, it's attempting to remove a constraint called:
FK_dbo.Events_dbo.Courses_Course_Id
There is one called:
FK_Events_Courses_Course_Id
which I presume EF4.1 made.
Unfortunately this causes an SQL error, yet the migration thinks it's completed fine.
Any ideas anyone?
@Iain M Norman – Can you start a StackOverflow thread using the entity-framework tag and provide some more details about how to reproduce this issue.
Is EF5 has been shipped with Unique Constraints as described in – blogs.msdn.com/…/unique-constraints-in-the-entity-framework.aspx ??????? Please confirm.
@Morshed: Unfortunately unique constraints did not fit in EF5 release.
I can't believe you guys still haven't fixed the depluralrization problem with entities that end with "Status".
I don't think this is specific to Entity Framework 5. I had a field that used byte as a primary key. I don't know if this is good practice but it ran OK in SQL server and even in entity Framework. Once I converted my code to use Code First I ran into a problem to add new data to this table. When I run SaveChanges the application gives me an error. I debugged the code and found that SaveChanges is unable to generate the primary key for the newly added row. I didn't get this error when I was using edmx.
All the changes are killing us. So many things have been moved around now that I have to refactor half our codebase in the db layer if we want to move to EF5. Right now I'm trying to find out where mergeoption disappeared to among other things…
@zl1 – Improving the pluralization service was something that just didn’t fit into EF5. You can track the issue here entityframework.codeplex.com/…/183
@James Portelli – By default Code First can only create a database that generates values for GUID and Integer columns. If you are using Migrations you can always use the Sql method to add some logic that sets up some logic to generate values for a Byte column in the database. If you don’t do this then you’ll need to set the value on new objects before saving.
@efygbfkm – There shouldn’t be any required changes to move to EF5. I suspect you are referring to moving from ObjectContext to DbContext. This is optional and ObjectContext remains as a fully supported and valid option. Within the EF Designer, existing models that use ObjectContext will continue to do so unless you decide to switch over. New models will use DbContext by default but you can always swap to ObjectContext – msdn.microsoft.com/…/jj556581
@Paul Marvin – I'll follow up on the StackOverflow thread shortly.
Are compiled queries available with DbContext yet? It will be rather infuriating if it was left out yet again.
@Kyle – Queries are now automatically compiled and cached.
Thanks for your reply Rowan.
I still have not started looking into programming WinRT applications for Windows 8. I would really love to but I hear that .NET data classes are not supported. Is there anything planned to bring entity framework to WinRT applications ?
@James Portelli – Correct, EF isn't available in WinRT applications. We are looking at data access for WinRT at the moment and investigating if EF is the right thing to make available.
Any example of using EF5 in WPF, with full client binding and data manipulation and changes rollback?
Thanks Rowan. Very kind of you.
I wonder why Microsoft didn't think about this before. What is an application without data ?
Is there a way to handle data in WinRT at the moment ? I heard of OData but can this be used with SQL server ?
@VRassouli – Here is an EF/WPF walkthrough msdn.microsoft.com/…/jj574514
That page doesn't address rollback, but you can use context.Entry(myObject).Reload() to revert to what is in the database. Alternatively you can set the current values to the original values using the techniques discussed on this page – msdn.microsoft.com/…/jj592677
@James Portelli – A service based architecture is definitely the recommended option for accessing a remote database. Both Web API and WCF Data Services (OData) integrate well with EF, head to this page for more info – msdn.microsoft.com/…/jj613668
Something like EF is more interesting for storing local data for your applications.
I keep hearing (reading) that in the new EF5:
"New models created using the EF Designer in Visual Studio 2012 will now generate a derived DbContext and POCO classes by default."
"New models will use DbContext by default but you can always swap to ObjectContext"
etc… and so on, but every time I create a new model, either generated from database or empty, the Code Generation Strategy is still set to "Deault" when created, and using ObjectContext/EntityObjects, no DbContext/POCOs. Do I need to configure this as a hidden default setting in VS 2012?
Thanks for any advice!
@Fernando Espinosa – You don't need to do any configuration, you should just get DbContext by default. If you aren't seeing this can you start up a StackOverflow thread with the entity-framework tag so that we can investigate why.
EF5's Code First does not support sequences in SQL Server 2012.
Anyone else having problems with the EntityObject T4 template not auto-compiling during save of the EDMX despite the "Transform Text Templates" option being true and the TT template being a dependent of the EDMX?
@Paul Marvin – Is your EDMX in a folder? You are probably hitting this bug – entityframework.codeplex.com/…/453
@Rowan Miller – yep, I think you're 100% correct, all of my models are under a Models folder as well as a model specific folder, thanks for the heads-up
EF Team,
After unsuccessfully searching for an answer, I have chosen the best and the brightest to point me in the right direction.
I want to implement blob storage for uploaded images and documents; so of course, all my searching points me to Azure. Azure is great, wonderful, and excellent for implementing blob storage–no complaints here. However, I am hosting my MVC4 CodeFirst (.net 4.5) site on my equipment (Windows 2008R2, IIS7, SQL Server 2012.) I cannot seem to find any information on CodeFirst and FileTable. Correct me if I'm wrong, but proper blob storage would be a FileTable data type in SQL Server. Can EF handle this data type? I can't find anything when searching on FileTable except SQL Server specific results.
There are plenty of examples of uploading images, storing them on the file system, and saving a pointer in the database. I don't believe this is a good practice. For one, a publish will blow-out uploaded images. I could get around this issue–but I want to do it right.
I apologize for a post in an inappropriate place.
Sean Stenlund
@Sean Stenlund – EF doesn't have support at this stage, you would need to use a raw sql query to fetch the data msdn.microsoft.com/…/jj592907
@Rowan Miller Thank you for the reply. Sounds like I should add it to the Feature Suggestions–if it isn't already there. Basically, I want to implement something similar to Azure Blob Storage without using Azure. Like I said, Azure is great, but we already have an investment in our own equipment and our storage/throughput is not substantial.
So, basically, this release is useless with .NET 4.0 since there is nothing new and all features require 4.5? Very disappointing.
@Georgij Sapkin – Yes, unfortunately with parts of EF still in the .NET Framework we needed to update them to implement the bigger features. So on .NET 4 you just get bug fixes and other minor improvements.
The good news is that in EF6 everything will be moved into the out-of-band assembly and all the EF5 features will start working on .NET 4. In fact, that work is already checked into our code base.
Any plans for an EF6 Beta?
@Andre.Ziegler – No exact dates yet, but we are working on the release at the moment and I think we'll make it available in the next month or so. In the mean time you can use the nightly builds to check out some of the new features. blogs.msdn.com/…/ef-nightly-builds-available.aspx
@Rowan Miller
Per my question about FileTable above; I see how using raw SQL to fetch the data will work. However, if I'm using CodeFirst and add the FileTable in SQL, I'll have a mismatch between the model and the database. So, I should add the FileTable via a migration. Right? So what would the CreateTable() look like? Especially since you don't create fields in a FileTable.
CreateTable("dbo.MyFileTable", c => new { ? })
Can you use raw SQL in a migration?
Thanks for your help,
Sean
@Rowan Miller
do the nightly builds work with VS2010 and .net 4.0? I want to try the enum support.
@Andre.Ziegler – Yes, we haven't done much testing of it yet but in general it should work.
@Sean Stenlund – The easiest approach is probably to use raw SQL, you can use the Sql(string) method in your migration to do this.
I have a question about the EF Designer in VS2012. When I open a EDMX file which is created with VS2010 and EF4, the designer is no longer loaded I can only see the XML. How can I get the designer back?
With the performance benefits of EF5, is it still beneficial to use the pre-generated views feature from EF Power Tools Beta 2?
@Patrick Tran: Performance improvements in EF5 did not focus on view generation but on auto compiling queries and generating faster/smaller SQL queries. If you identified view generation causing your app to start slowly then you may want to try if it helps. If you see performance problems when the app is running it's unlikely that it is caused by view gen and using pre-generated view will probably not help.
@Patrick Tran: Yes, you might still take advantage of pre-generated views if you have a very large or complex model that introduces a "warm up" delay when you execute your first query or the first call to SaveChanges. Please refer to our whitepaper Performance Considerations for Entity Framework 5 for more details: msdn.microsoft.com/…/hh949853.aspx.
@Andre.Ziegler – I believe we answered this question for you in another place, but I just wanted to reply here for folks reading these comments. This occurs when the EF Designer is not selected for installation when installing VS. Unfortunately the EF Designer isn't grouped under the most obvious headings, when doing a custom install of VS2012 either 'SQL Server Data Tools' or 'Web Developer Tools' must remain selected for the EF Designer to be installed.
@Rowan Miller
yes, Brice Lambson explained it on codeplex:
entityframework.codeplex.com/…/401836
but this is confusing. Rename it to Database Development Tools in the next VS or better make an extra option to install the EF Designer.
@Andre.Ziegler – We totally agree and will address it in the next release, we've opened this item to track the issue – entityframework.codeplex.com/…/673.
@Rowan Miller
ok 🙂
We're currently using EF 4.1 code first with SQL Server 2005. Will we still see the improvements in performance for EF5 even though we're using an older version of SQL Server? Will EF6 continue to support SQL Server 2005?
@Stephen: Once you install .NET Framework 4.5 you should see perf improvements introduced in EF5 since they were done in the EF5 component that lives in the .NET Framework (System.Data.Entity.dll) which is used by EntityFramework.dll you are using. EF6 supports Sql Server 2005.
Not bad, 5 versions to get to production-ready. Another 5 versions to catch up? weblogs.asp.net/…/differences-between-nhibernate-and-entity-framework.aspx
i referened the ef5,used [RelatedTo],occur "The type or namespace name 'RelatedTo' could not be found" ,why?
@The type or namespace name 'RelatedTo' could not be found – RelatedTo was an old attribute used in some early previews of Code First. In the final versions you use the InverseProperty and ForeignKey attributes. This page has a section that shows how to use them – msdn.microsoft.com/…/jj591583.
I have a database with 800 tables.Im new with Entity Framework. Until know i wrote my custom classes by myself
and i used ADO NET to communicate with SQL Server. My Questions are
1) Can Entity framework manage a large database?
2) Is it easy for maintainance?
3) Must multi part my model?
Thanks
@Manos Frog – You shouldn't have issues with that many entities. You will definitely want to review the performance considerations though – msdn.microsoft.com/…/hh949853.
I would consider using Code First because 800 entities is a lot to take in visually on the design surface – although we do support having multiple diagrams per model in EF5. Separate classes will also be nicer to review changes in source control – as opposed to one large xml file.
Here is a short video that covers the various options you have for modeling – msdn.microsoft.com/…/jj590134.
Thank you Rowan Miller ! I will read these articles!