简体   繁体   English

如何在ASP.NET MVC 5应用程序和.NET控制台应用程序之间共享数据库?

[英]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.

相关问题 如何在父控制台应用程序和ASP.NET Web应用程序之间共享app.config - How to share app.config between parent console application and ASP.NET web application 如何从控制台应用程序在 ASP.NET MVC 应用程序中进行身份验证 - How to authenticate in an ASP.NET MVC application from a console application ASP.NET MVC运行控制台应用程序以更新数据库 - ASP.NET MVC Running a console application to update a database 如何在WPF和ASP.NET MVC应用程序之间共享最多代码? - How to share the most code between a WPF and an ASP.NET MVC application? 如何在PHP和ASP.net应用程序之间共享会话? - How to share sessions between PHP and ASP.net application? 如何从控制台应用程序将文件上传到 ASP.NET MVC - How to upload a file to ASP.NET MVC from a console application 在ASP.NET Core中的应用程序和子应用程序之间共享Cookie - Share Cookie between application and sub application in ASP.NET Core 从linqpad或控制台应用程序运行asp.net mvc应用程序 - Run asp.net mvc application from linqpad or console application asp.net 内核中的控制台应用程序和 Web 应用程序之间的区别 - Difference between a console application and Web application in asp.net core 跨ASP.NET MVC应用程序共享数据 - Share Data across ASP.NET MVC application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM