Entity Framework 7 (EF7) is a lightweight and extensible version of Entity Framework that enables new platforms and new data stores. Explore how EF7 achieves those goals, and see helpful demos of EF7 in action.
Why do we have to do option.UseSqlServer in the DbContext on Configuring override and also AddSqlServer in the Startup.cs ConfigurationServices method?
What's the difference between these two?
@scyonx: UseSqlServer is telling EF that you are targeting SQL Server for that particular context instance. AddSqlServer is about registering services with the global ServiceProvider. If you had two contexts - one targeting SQL Server and the other SQLite - you would add the services for both providers in Startup.cs but only configure the appropriate one to be used by each context.
While you can use ServiceProvider in other types of applications, the pattern will mostly just be used in ASP.NET 5. EF works just fine without creating an external ServiceProvider and passing it in. You can just create a context, call UseSqlServer in OnConfiguring and EF will take care of creating the required services internally. But if you did this in ASP.NET 5 you would loose global logging etc.
Hi Rowan, Is there a tutorial on how to migrate from an existing database to EF7?
Terrific work, very excited. Thanks,
I cloned EF7-demo and took a look. This opens in VS 2013 by default. It's based on EF7 beta 1. Using the MVC project, I did not see how this would relate to the demo in the video.
So, I then tried to open a new VS2015 CTP5 asp.net 5 starter project and duplicate some of your steps in the video. The option of using K EF in command line did not work at all. I was in the right dir, but reflection errors came up and EF dll did not load.
Perhaps the demo project on Github can be updated to EF7-beta2 and VS2015 CTP5.
k : System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the
LoaderExceptions property for more information.
At line:1 char:1
+ k ef
+ CategoryInfo : NotSpecified: (System.Reflecti...re information.:String) , RemoteException
+ FullyQualifiedErrorId : NativeCommandError
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.TryGetEntryPoint(Assembly assembly, IServiceProvider
serviceProvider, Object& instance, MethodInfo& entryPoint)
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String args, IServiceProvider
at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String args)
at Microsoft.Framework.ApplicationHost.Program.Main(String args)
I noticed at 21 minutes in, it was stated that having a database and building a code-first model from an existing database is a supported workflow. Are the tools currently available for EF7 to try this feature out? I can't seem to find this anywhere!