[英]How to share a database between ASP.NET MVC 5 application and .NET console application?
I have two projects in separate solutions - an ASP.NET MVC 5 application and a console application - using the same database. 我在单独的解决方案中有两个项目-ASP.NET MVC 5应用程序和控制台应用程序-使用同一数据库。 Both of them using Entity Framework Code First migrations . 它们都使用Entity Framework Code First迁移 。 Each project uses a duplicate of the models (that is, each project uses the same models, I have just copied and pasted the class files into each solution). 每个项目都使用模型的副本 (也就是说,每个项目都使用相同的模型,我刚刚将类文件复制并粘贴到每个解决方案中)。
What is a better way to handle changes to the models? 有什么更好的方法来处理模型更改? For example, if I were to update the models in the web project, I would then need to copy and paste the files over to the console application and vice versa. 例如,如果要更新Web项目中的模型,则需要将文件复制并粘贴到控制台应用程序中,反之亦然。 Not to mention this, with each change I constantly have a headache of trying to update the database twice from each project. 更不用说了,每次更改时,我总是很头疼,试图从每个项目中两次更新数据库。 Any suggestions? 有什么建议么?
I have seen some suggestions about moving resuable code (ie the models) into a class library. 我已经看到了一些有关将可恢复代码(即模型)移入类库的建议。 However, my DB Context for the Web applications uses the Identity models whilst my console application does not. 但是,我的Web应用程序的数据库上下文使用身份模型,而我的控制台应用程序则没有。 Will this be an issue? 这会是个问题吗?
Thanks. 谢谢。
我通过制作一个包含项目之间通用的所有模型的类库并将其发布到我们的私有NuGet服务器来解决此问题,这样,如果正确设置了nuget,更新和更改将自动从nuget中提取服务器(如果有)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.