dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.66k stars 3.16k forks source link

Guidance: How to use EF6 with ASP.NET Core 1 RC2 web app? #2336

Closed ToddThomson closed 1 year ago

ToddThomson commented 9 years ago

I've been moving a subset of my MVC 5, EF6 application to ASP.NET 5, MVC 6 and EF7 and I really like the direction that the platform is moving to. Moving to EF7, however, poses many issues for me. It is just too short on required features that I have used in EF6. I feel I will be investing a great deal of time to add workarounds and to deal with the limitations. So, what is the guidance for using EF6 with an ASP.NET 5 application? I have my database services and repository code in separate libraries (I have essentially a dll for each derived type + a dll for a base type ). Any help would be very much appreciated!

matguthrie commented 8 years ago

Hi,

I'm encountering the same "Exception calling "SetData" with "2" argument(s)" issue when calling add-migration. I have a separate data project using EF 6.1.3 and have been using migrations successfully with a ASP.NET 4.5 project. I've just added a ASP.NET 5 web app to the solution and I'm now unable to add a migration. The target project is the data project itself.

If I remove the ASP.NET 5 project from the solution I can add the migration without issue, although adding and removing the project every time i want to update the DB is not ideal

Any suggestions?

Mat

mrahhal commented 8 years ago

@matguthrie If you're talking about Migrator.EF6 (I can't figure out from the context) please open an issue in that repository.

ToddThomson commented 8 years ago

@rowanmiller Just thought I'd review this question for the upcoming ASP.NET Core 1 RC2 release which I plan to test out next week.

Will EF Core 1 RC2 and EF6 still work together in the same web project? Will there be any tooling for migrations for EF6 in VS2015 preview 1 tooling support? Are migrations supported in VS Code? Is there any likelihood that TPT will be provided in EF Core 1 this year?

My web app targets the full framework, and I require TPT so EF6 is my only option for now.

Thanks in advance!

rowanmiller commented 8 years ago

@ToddThomson The state in RC2 will be the same as RC1. You can use EF6/EF Core side-by-side, but there is no xproj compatible migrations tooling for EF6. In VS Code you would use the dotnet ef ... command line tooling for migrations (EF Core only).

mrahhal commented 8 years ago

@ToddThomson the same way Migrator.EF6 has been done to work with migrations in dnx, a cli tool can be created for EF6 migrations to work in RC2 as well.

And since the state will be the same, we'll still be able to use all features of EF6 in RC2.

mrahhal commented 8 years ago

For anyone who found this useful in dnx, Migrator.EF6 now supports RC2 as a .NET Core CLI tool (much like how the EF Core migration tool works).

aman-saggu-git commented 8 years ago

Hi Everybody , I have a question if I use below Code Then I think I will be using Entity Framework Not (.Net Core ) or I am making mistake

{ "dependencies": { "EntityFramework": "6.1.3" }, "frameworks": { "net461": { } } }

rowanmiller commented 8 years ago

@bhallaheemanshu correct, that would be using EF6.x in an app that targets full .NET.

aman-saggu-git commented 8 years ago

@rowanmiller Can we achive scaffolding for asp.net core with Ef core

rowanmiller commented 8 years ago

@bhallaheemanshu are you asking about scaffolding an MVC controller and views from and EF Core model? If so, then yes, that is supported.

Eisenstein commented 8 years ago

@mrahhal I'm getting an error 'No executable found matching command "dotnet-ef"' What could be wrong?

mrahhal commented 8 years ago

@Eisenstein please check the repo's issues (there's a good chance you'll find it) or create a new one.

aman-saggu-git commented 8 years ago

@rowanmiller any link suggestion to use scaffold & Migrations in rc2

marchy commented 8 years ago

@mrahhal We get the following error when running any of the migration commands: Value cannot be null. Parameter name: type

Any idea how to trouleshoot this? Our setup runs fine at runtime (ASP.NET Core app) but the migration commands don't like it

UPDATE(solved): We had "emitEntryPoint" set to false instead of true in project.json. This fixed it!

Bruce247 commented 7 years ago

Hi all. I am also getting a 'No executable found matching command "dotnet-ef"' error when attempting to run "dotnet ef migrations add InitialDatabase" at the command prompt. I am running the command in the same folder as project.json, and ""emitEntryPoint": true,". What else can I try???

mrahhal commented 7 years ago

@Bruce247 if it's a problem with Migrator.EF6 please check the issues on that repo first and then create an issue if you still can't get it to work. In particular you should check mrahhal/Migrator.EF6#9.

Bruce247 commented 7 years ago

@mrahhal Thanks for your response. I'm afraid I have no idea if my issue is a 'migrator.EF6' one. I just don't have enough knowledge of these things right now. I tried suggestions at https://github.com/mrahhal /Migrator.EF6/issues/9 & https://github.com/mrahhal/Migrator.EF6/issues/9, but produced more errors than solutions, and had to revert it all. I'm really just interested in finding the simplest way to get Shawn's code to work. A step-by-step for that would be wonderful! I fear I will have to abandon this course, which I really, really wanted to complete! :-) Thanks again! My (reverted) project.json code is as follows: `{ "dependencies": { "jQuery.Validation": "1.15.1", "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.1", "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.1", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.EntityFrameworkCore": "1.0.1", "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", "Microsoft.EntityFrameworkCore.Tools": { "version": "1.0.0-preview2-final", "type": "build" }, "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" } },

"tools": { "Microsoft.AspNetCore.Server.IISIntegration.Tools": { "version": "1.0.0-preview2-final", "imports": "portable-net45+win8+dnxcore50" } }, "Microsoft.EntityFrameworkCore.Tools": { "version": "1.0.0-preview2-final", "imports": [ "portable-net45+win8+dnxcore50", "portable-net45+win8" ] },

"frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", "portable-net45+win8" ] } },

"buildOptions": { "emitEntryPoint": true, "preserveCompilationContext": true },

"runtimeOptions": { "configProperties": { "System.GC.Server": true } },

"publishOptions": { "include": [ "wwwroot", "web.config" ] },

"scripts": { "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] } } `

mrahhal commented 7 years ago

@Bruce247 ah sorry about that. Looks like you're using EF Core, so you have nothing to do with Migrator.EF6. Hmm honestly not sure what's wrong here, your project.json looks good but there might be something I've missed.

rowanmiller commented 7 years ago

Closing this issue as discussion has got very off track from the original "using EF6 in an ASP.NET Core app" topic.

@Bruce247 please open a new issue with the problem you are facing.