简体   繁体   English

为2个项目拥有一个DAL实体框架

[英]Having one DAL for 2 projects Entity Framework

I have 2 projects currently. 我目前有2个项目。 A dashboard(MVC) and a API. 仪表板(MVC)和API。 both of them look at the same database but have their own models generated in their respective projects so if you make a change to one it doesn't reflect in the other one. 他们两个都看同一个数据库,但是在各自的项目中生成了自己的模型,因此,如果对一个数据库进行更改,则不会反映在另一个数据库中。

I want to add a third project for the data and have both my other projects look at that project for any data queries. 我想为数据添加第三个项目,让我的其他两个项目都在该项目中查看任何数据查询。

What would be the simplest way of doing this and how would the context of EF be affected with the queries sitting in a separate project from where the data is used. 这样做的最简单方法是什么,并且与位于使用数据的位置不同的项目中的查询会如何影响EF的上下文。

Create a separate project for your Data Access Layer (EF en entities). 为数据访问层(EF en实体)创建一个单独的项目。 Then create a reference to this separate project to use it. 然后创建对该单独项目的引用以使用它。

在此处输入图片说明

Do not forget to add the connection string and entity framework setting to your .config file. 不要忘记将连接字符串和实体框架设置添加到您的.config文件中。

在此处输入图片说明

When do not work with code first and in your project you work with multiple Data layers, it may be required you add some metadata to the connection string. 如果先不使用代码,并且在项目中使用多个数据层,则可能需要在连接字符串中添加一些元数据。

I hope this helps u. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM