Thanks, ben for getting me back on track with ef core. Return new pinchcontext(builder.options) Var builder = new dbcontextoptionsbuilder() īesqlserver("server=(localdb)\\mssqllocaldb database=pinchdb trusted_connection=true multipleactiveresultsets=true") Public pinchcontext create(dbcontextfactoryoptions options) Public class temporarydbcontextfactory : idbcontextfactory the tools would normally gather this information from your startup.cs, but since that would be a huge pain to implement, let’s cheat and create an idbcontextfactory instead.Īdd the following class to your class library: Lastly, we need to let our fake app know how to create your dbcontext. One last thing that ben mentions is that our fake app (the program.cs) needs to know how to create a dbcontext. it will recompile your code and everything should be ok. dotnet ef dbcontext scaffold "server=localhost database=mydatabasename trusted_connection=true " -output-dir models/efĬommand from above at the command-line. - used this to generate ef scaffolding at the command line in the root of the project: In an empty program.cs and place it into your root of the class library. It seems this is an issue with ef migrations core rtm and is acknowledged as a problem. So, i decided to talk to my other best friend-google.Īfter searching for 15 minutes, i found a well-written post by ben cull aboutĮntity framework core migrations in class library projects With the project.json in good shape, i tried to generate the entities again by using the command-line in the project directory.ĭotnet ef dbcontext scaffold "server=localhost database=mydatabasename trusted_connection=true " -output-dir models/efĪfter waiting for a couple of seconds, i receive this little message:Įrror cs5001: program does not contain a static 'main' method suitable for an entry point Nope, nothing looked weird in the project.json. Ok, do we have everything to generate the entities?Īfter thinking i didn't have an assembly installed, i looked over the I was going through everything in my head: Thinking i could generate my new entities using the I wanted to keep my data layer in a separate assembly because, well. This weekend, i was wrestling with the issue of generating entity framework entities in an asp.net core 1.0 class library. Over the past months, i've been slowly converting my cms over to asp.net mvc/ef/identity core 1.0 and implementing pieces as they become more stable. Add Data Connection in Server Explorer Add EntityFramework Plugins Scaffolding Operation Add Connection String to appsettings.json Add DbContext to Startup.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |