-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guidance: How to use EF6 with ASP.NET Core 1 RC2 web app? #2336
Comments
@julielerman has an article in the latest MSDN magazine on how to do that! |
in "dependencies": {
"EntityFramework": "6.1.3"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
} //, "dnxcore50": { }
} |
Here's a link to the article: https://msdn.microsoft.com/en-us/magazine/dn973011.aspx. Separation of Concerns is your friend here. Just have your data access (EF) stuff with EF6 in its own project (or projects if you ahve multiple models). HTH (& thanks @ErikEJ ) |
Thanks @ErikEJ and @julielerman ! I've just finished reading through your article. It cleared up a bit of confusion on the project.json use of the "frameworks" property. I really have no need for dnxcore50 at the moment so I've just removed that framework. |
@mundi4 Just saw your post - that's exactly what I did. Thanks. |
I don't think that is true because you can't have two different versions of the same assembly loaded in an AppDomain. BTW there is some discussion on an EF6 provider for ASP.NET 5 Identity which would solve this issue aspnet/Identity#416. |
@rowanmiller Thanks. I was just about to test it out. I'll edit my post above. |
I've determined that the powershell scripts to enable migrations (etc) in the EF6 6.1.3 nuget package are not installed when the web application project type is the new ASP.NET 5 XPROJ type. I can understand the reasoning behind this. However, as I mentioned in the starting post for this issue, I cannot use EF7 due to its lack of features compared to EF6. Is there a chance that the DNX team and the EF team can come together to provide ASP.NET 5 XPROJ + EF6 migrations support? |
@ToddThomson at this stage the ASP.NET 5 xproj system does not process the PowerShell files that can be included in a NuGet package. If you want to add your vote toward this feature then here is the place to do so aspnet/dnx#952. |
What features in particular are blocking you from using EF7? I'd like to understand if they are things that will be implemented by the initial RTM of ASP.NET 5 and EF7 or whether they are things that will still be missing once we move beyond pre-release. |
@rowanmiller The things that I believe are blocking me from porting my MVC5, EF6 content management system to EF7 are:
I hope that helps. |
@ToddThomson I'll come back to the features in the next couple of days 1 and 2 are possible but the code looks a little different. 3 is not possible at the moment.
I think you will be able to manually run |
@rowanmiller Thanks. I'll try the manual install later today. |
@rowanmiller A simple way to get EF6 commands to work in an ASP.NET 5 XPROJ solution is to add an empty CPROJ project and add EF6 6.1.3 nuget package to both. At that point you can run enable-migrations, etc ( EF6 commands ).
The code at that location is:
I'll investigate a bit more, but it looks like a dead end. |
Looping in @cherrydev as I am told they have already looked at enabling migrations in EF6/ASP.NET5 scenarios. They may be able to share some of their finding here. |
Regarding the features you mentioned...
We may introduce an API similar to what we had in EF6. But because we changed the model builder to construct the model as it goes (rather than at the end based on the config you supplied) you can query the model and configure based on it's current shape. i.e. this code achieves what your sample did on EF6 protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (var type in modelBuilder.Model.EntityTypes)
{
if(type.ClrType.CustomAttributes.Any(n => n.AttributeType == typeof(CoreContentEntity)))
{
modelBuilder.Ignore(type.ClrType);
}
}
}
You can still model the many:many pattern, you just need to have the join entity be part of your entity model (i.e. you would have a
Correct that this isn't supported yet. If modifying the core table was a possibility then we are introducing support for TPH at the moment. |
Are we looking at a production release of EF7 along with VS2015? I'm looking at migrating an existing production MVC4 + EF6 project to vNext. If EF7 isn't coming out soon and EF 6 isn't fully compatible with new VS then I might as well wait a little longer before I migrate. |
@yashvitnaik EF7 will become RTM at the same time as ASP.NET 5 (MVC6). Neither of these will be at the same time as VS2015 RTM (both will still be preview in the VS2015 RTM). The ASP.NET team is working on making their dates public. |
@rowanmiller TPT is a must have for me to use EF7. I've investigated the alternatives, but I can't make TPH or TPC work. I'll come back to using EF6 and ASP.NET 5 when VS 2015 goes RTM. My hope is that EF6 migration commands will work and that there will be an identity 3 with an EF6 component dependency. |
@ToddThomson we actually just took a series of package/assembly renames so you will be able to have EF6/EF7 running in the same app (so you can use Identity 3 and still use EF6 for your data access). |
@rowanmiller Perfect. Is TPT on the radar for EF7? Edit: This is all good, but vs2015 not being able to run EF6 migration commands will be trouble ( which is the case right now ). |
@ToddThomson not for the initial RTM. We will evaluate after that to see what we want to support beyond TPH for EF7. |
@rowanmiller For SxS scenario, I can have a VS2015 ASP.NET 5 xproj which has dependencies on EF6 and EF7. The problem is that the power shell scripts for EF6 ( migrations ) only work with csproj projects. Are the EF6 migrations going to be updated to support vs2015 ASP.NET 5 xproj type? |
Perhaps dnx . ef6 ... |
I have EF6 migration commands working in DNX but I've repeatedly asked for someone with commit access in ASPNET for help actually getting them into a public repository and haven't yet gotten a solid response. |
@cherrydev Given the recent changes to have EF6 and EF7 SxS, hopefully the ASP.NET 5 team will be more receptive to EF6 migrations working with DNX. |
@ToddThomson @cherrydev xproj is going to support loading commands in Package Manager Console, so the EF6 commands will start working. |
@rowanmiller Thanks. Is the xproj support for EF6 commands in vs2015RTM? |
@ToddThomson we did rename the EF7 We are working on Init.ps1 support... but I don't have an exact time that it will light up (before RTM, but I'm not exactly sure what release). |
@rowanmiller Good decision. I can now move to Identity 3 and what I can to EF7 and wait for TPT/TPC. Thank-you for the update! |
Hi guys! In case somebody is looking for an example of how to make Identity 3.0 to utilize EF6 instead of EF7, I have published my implementation here: https://github.com/entrypointsoft/AspNet.Identity.EntityFramework6 |
Another sample here: https://github.com/OneBitSoftware/Microsoft.AspNet.Identity.EntityFramework6 |
For anybody looking for a dnx based EF6 migrator, I've implemented one here: Migrator.EF6. |
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 |
@matguthrie If you're talking about |
@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? My web app targets the full framework, and I require TPT so EF6 is my only option for now. Thanks in advance! |
@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 |
@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. |
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). |
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
|
@bhallaheemanshu correct, that would be using EF6.x in an app that targets full .NET. |
@rowanmiller Can we achive scaffolding for asp.net core with Ef core |
@bhallaheemanshu are you asking about scaffolding an MVC controller and views from and EF Core model? If so, then yes, that is supported. |
@mrahhal I'm getting an error 'No executable found matching command "dotnet-ef"' |
@Eisenstein please check the repo's issues (there's a good chance you'll find it) or create a new one. |
@rowanmiller any link suggestion to use scaffold & Migrations in rc2 |
@mrahhal We get the following error when running any of the migration commands: 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! |
Hi all. |
@Bruce247 if it's a problem with |
@mrahhal "tools": { "frameworks": { "buildOptions": { "runtimeOptions": { "publishOptions": { "scripts": { |
@Bruce247 ah sorry about that. Looks like you're using EF Core, so you have nothing to do with |
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. |
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!
The text was updated successfully, but these errors were encountered: