30

Getting exposed to dotnet Core. In a sample test application trying to setup EntityFramework.Core in dotnet core app. While I was able to add the EntityFramework.Core NugGet package I can't find the 'Add'->'New Item'->'Data'->'ADO.NET Entity Data Model'

Is this not possible with EntityFramework.Core?

How does EntityFramework.Core differ from EntityFramework 7?

Tseng
  • 61,549
  • 15
  • 193
  • 205
barrypicker
  • 9,740
  • 11
  • 65
  • 79
  • 2
    Possible duplicate of [Is there an Entity Framework 7 Database-First POCO Generator?](http://stackoverflow.com/questions/29300777/is-there-an-entity-framework-7-database-first-poco-generator) – Igor Sep 20 '16 at 17:56
  • 1
    EF7 was renamed to EF Core after the RC1 release. – bricelam Sep 22 '16 at 15:50
  • 8
    They close the question because of someones opinion this is not focused enough. This is why SO will die a slow death. This question clearly has value and interest since it has been viewed 12,000 times. Also, a relevant answer was added only a couple of months ago. Status updates on a technical concept help future viewers understand the current state for older technologies. Since the moderators closed this question nobody can update the status of this question in the future. Bummer. – barrypicker Jun 30 '20 at 18:32
  • 2
    @barrypicker Perhaps vote to reopen? Your comment is valid. Let's do something about it. – Rob Scott Jul 15 '20 at 07:14
  • 1
    @RobScott - thanks for the words of encouragement - I voted to reopen... – barrypicker Jul 15 '20 at 22:42
  • The question was closed mainly because there are two very different questions in it. Therefore "needs more focus". Closing totally made sense and stil does. – Gert Arnold Jul 16 '20 at 12:27

4 Answers4

24

There is no edmx support in Entity Framework Core. It only supports a code-first approach. The option to add a new Entity Data Model will be added, but it will produce entity class files instead of an edmx file. The tooling development is a little bit behind the framework development currently.

Mike Brind
  • 28,238
  • 6
  • 56
  • 88
  • Hi @Mike, thanks for the response. If no EDMX, how to write LINQ queries against the database? Could you provide a basic example? – barrypicker Sep 20 '16 at 20:17
  • 2
    You should spend a bit of time reading the official docs: https://ef.readthedocs.io/en/latest/ – Mike Brind Sep 20 '16 at 20:42
  • 1
    https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db To get started with an existing database this doc covers that. – Greg Jan 12 '18 at 17:16
  • 2
    @Greg Yes, but you will be forced to use code-first migrations after the initial setup. For those who can't modify the database and keep relationships in the edmx file, moving to core is, unfortunately, not possible yet. – umutesen Mar 12 '18 at 09:57
  • 5
    @Esen I have to fully agree. Without full support for database first tooling, it doesn't make sense for those who rely on such to switch over. (This limitation is the primary thing keeping me off Core.) – Greg Mar 12 '18 at 17:15
  • 1
    Yes. This very important. Without edmx auto generation the beauty of framework is still missed. You cant focus on development otherwise. – Liakat Hossain Jun 07 '18 at 20:05
  • @MikeBrind The link (https://ef.readthedocs.io/en/latest/) you provided seems dead? – Souvik Ghosh Jun 29 '18 at 11:39
  • @SouvikGhosh take a look at my site instead, then: https://www.learnentityframeworkcore.com – Mike Brind Jun 29 '18 at 12:15
  • I think this feature is expected to be launched with EntityFrameworkCore 3 – Vishal Feb 15 '19 at 10:13
  • @Vishal There is nothing in the 3.0 Roadmap, or the backlog that suggests that EDMX will be reintroduced. – Mike Brind Feb 15 '19 at 10:44
  • An option to scaffold (generate code) from an existing EDMX file would have been nice. The current scaffold option do not allow you to choose objects and any customization is lost. –  Aug 29 '19 at 13:55
19

Still no EDMX support yet for .Net core. To generate the dbcontext and entities from database, run below command in package manager console:

Scaffold-DbContext "Server=yourserver;Database=yourdatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

See details in https://learn.microsoft.com/en-us/ef/efcore-and-ef6/porting/port-edmx

You will need these packages:

Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.SqlServer.Design

https://ef.readthedocs.io/en/staging/platforms/aspnetcore/existing-db.html#install-entity-framework

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
suomi-dev
  • 848
  • 1
  • 13
  • 22
4

You can take advantage of edmx in dot net core, but only as a reference in order to create the classes that you need.

To do so, you have to add to your solution a project targeting dot net framework 3.5 or higher in order for edmx to work, add an existing edmx file from another, older project because visual studio 2019 does not have that template available, now you can clean it and add entities from sql server.

In the others dot net core project, you have to add t4 templates file .tt these files are going to read the edmx file through the file system path. You have to edit the .tt files in order to work with dot net core.

Once again, you don't need to reference the dot net framework project, it only exists so edmx can work.

Chris
  • 1,206
  • 2
  • 15
  • 35
  • This is the solution I tried, because migrating our logic to code first is no option at the moment. I created a second project (.net framework), moved the edmx/tt file to that project. So we can update the model and just move the single generated file to the database project (as we generate all entities in one class). Thanks for your idea. – SVSchmidt Nov 28 '19 at 11:04
  • 1
    In .net core 3, a new version EF 6 became compatible with .net Core. Here are a few links after the new EF 6.3 has landed, about how to get the edmx stuff working using a workaround. They are planning to add edmx support, I asked "when" yesterday and the answer was, "not anytime soon" :). (https://github.com/aspnet/EntityFramework6/issues/883) So here you go: https://learn.microsoft.com/en-us/ef/ef6/what-is-new/#ef-designer-support https://github.com/efcore/EdmxDotNetCoreSample/ https://github.com/aspnet/EntityFramework.Docs/issues/1748 – Flemming Bonde Kentved Dec 06 '19 at 14:29
4

As an alternative to an EDMX, there is an open-source extension available to do visual modeling and generate code-first EF contexts and classes. It can consume both a compiled assembly containing a DbContext as well as existing entity class C# code to facilitate bootstrapping the model. Available at:

https://marketplace.visualstudio.com/items?itemName=michaelsawczyn.EFDesigner https://github.com/msawczyn/EFDesigner

Full disclosure: I'm the original author and maintainer.

Michael Sawczyn
  • 305
  • 3
  • 10