0

We are working on bringing an old web forms application into the MVC world. The old application was using an ORM called EntitySpaces, which we will now be switching to EntityFramework as well. Recently we ran into an issue because we are doing code first migrations in EF6 currently but it has no support to set default values via the fluent api, instead you must generate the migration and eidt it to have the default values. This feels dirty to us so we looked into EF core and found that it has a HasDefaultValue() method in the fluent API just like we want.

We are using .net 4.6 for this project because we still need webforms in the project until all the pages are migrated to razor views, then we can look at upgrading to .net Core. In the meantime can we use EF Core with .net 4.6 or does it require .net Core?

Nathan Kamenar
  • 824
  • 7
  • 30
  • Documentation is always a good starting point - [.NET implementations supported by EF Core](https://learn.microsoft.com/en-us/ef/core/platforms/) – Ivan Stoev Apr 06 '18 at 15:49
  • Thank you, I searched all over google and couldn't find a link to anywhere about compatibility or pre-requisites. – Nathan Kamenar Apr 06 '18 at 15:53
  • Misunderstood your last paragraph. I don't know that its possible to use EF Core with Web Forms. You can definitely use it with a MVC Core project that targets .NET Framework. – Valuator Apr 06 '18 at 15:54
  • It may seem a little weird, but you can also mix and match EF6 and EF Core. You can use EF Core for all your entities and migrations as well as any ASP.NET Core apps, and use EF6 as "code first with an existing database" for compatibility in legacy apps. Technically, since EF6 here is just using an existing database, there's nothing special about this. You could do the same with any ORM. – Chris Pratt Apr 06 '18 at 16:50

1 Answers1

2

Yes, it is. The Microsoft.EntityFrameworkCore package (https://www.nuget.org/packages/microsoft.entityframeworkcore) targets .NET Standard 2.0, which means it can be used by any runtime that supports it, such as .NET 4.6.1. See also https://learn.microsoft.com/en-us/dotnet/standard/net-standard.

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74