如何共享的ASP.NET MVC应用5和.NET控制台应用程序数据库? [英] How to share a database between ASP.NET MVC 5 application and .NET console application?

查看:187
本文介绍了如何共享的ASP.NET MVC应用5和.NET控制台应用程序数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同的解决方案,两个项目 - 一个ASP.NET MVC应用5和一个控制台应用程序 - 使用相同的数据库。他们都使用的实体框架code首先迁移即可。每个项目使用机型的重复(即每个项目使用相同的车型,我刚才复制并粘贴类文件到每个解决方案)。

I have two projects in separate solutions - an ASP.NET MVC 5 application and a console application - using the same database. Both of them using Entity Framework Code First migrations. 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).

什么是更好的方式来处理更改模式?例如,如果我是更新Web项目中的模型,我就那么需要将文件转移到控制台应用程序,反之亦然复制和粘贴。且不说这个,每一个变化我必须不断的从每一个项目在尝试两次更新数据库头疼。有什么建议?

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. Not to mention this, with each change I constantly have a headache of trying to update the database twice from each project. Any suggestions?

我看到有关移动可重复使用code(即模型)到类库一些建议。然而,我对Web应用程序的数据库上下文使用的身份识别模型,而我的控制台应用程序没有。这将是一个问题?

I have seen some suggestions about moving resuable code (i.e. the models) into a class library. However, my DB Context for the Web applications uses the Identity models whilst my console application does not. Will this be an issue?

感谢。

推荐答案

我已经通过了包含了所有的项目之间共同的模型一个类库,它发布到我们的私人的NuGet服务器处理这个,这样一来,如果的NuGet设置正确,更新和更改会自动从服务器的NuGet可用时拉出。

I have handled this by making a class library that contains all of the models that are common between the projects and publishing it to our private NuGet server, that way, if nuget is set up correctly, updates and changes will automatically be pulled from the nuget server when they are available.

这篇关于如何共享的ASP.NET MVC应用5和.NET控制台应用程序数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆