相同数据库的多个实体框架 [英] Multiple Entity Framework for Same Database

查看:105
本文介绍了相同数据库的多个实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在同一数据库的项目中创建多个实体框架吗?
我想为每个子系统创建实体框架。一些子系统有共享表。

解决方案

可以,您可以根据需要创建多个EDMX文件。



但不推荐,因为...


  1. 您不能查询不同的多个表模型。

  2. 定义边界将非常困难,因为大多数表通过关系连接。

  3. 如果在多个模型中存在相同的表,那么您将会出现一致性问题和命名空间冲突。

相反,我们只创建了一个EDMX模型,并将它放在一个通用库中,然后导入到许多不同的子项目中。唯一的问题是,必须正确定义连接字符串,指定公共库资源。


Can we create multiple entity framework in project for the same database? I want to create entity framework for each subsystem. Some of subsystem have shared table.

解决方案

It's possible, and you can create multiple EDMX files as you wish.

But it's not recommmended, as...

  1. You can not query multiple tables in different models.
  2. Defining boundary will be very difficult because mostly tables are connected through relationships.
  3. If same table exists in multiple models, then you will have consistency issues and namespace clashes.

Instead, we created only one EDMX model and put it in a common library, which is then imported in many different sub projects.The only problem is, your connection string has to be defined correctly specifying common library resources.

这篇关于相同数据库的多个实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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