简体   繁体   中英

Having one DAL for 2 projects Entity Framework

I have 2 projects currently. A dashboard(MVC) and a 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.

Create a separate project for your Data Access Layer (EF en entities). 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.

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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