0

首先使用 EF Db,我有两个表:

Table1: AppId, AppName, AppGuid [PK]

Table2: AppGuid [FK], Description, Url

EF 可以从两者中创建一个实体吗?

意义:

App: AppId, AppName, AppGuid, Description, Url

更新

谢谢。我提出了看法。将其映射到 EF。现在我收到以下错误:Error 2 Error 111: Properties referred by the Principal Role App must be exactly identical to the key of the EntityType MaMDBModel.App referred to by the Principal Role in the relationship constraint for Relationship MaMDBModel.FK_AppsData_App. Make sure all the key properties are specified in the Principal Role. D:\MaM\Dev\MamAdmin_1.0\MaMDBEntityFramework\MaMModel.edmx 768 11 MaMDBEntityFramework

这是我的 edmx:

http://ge.tt/3rRWTOR/v/0?c

4

1 回答 1

0

您可以在这两个表之间使用JOIN创建一个VIEW 。在此之后,您可以使用 EF 中的视图。

在 SQL 中执行此操作

CREATE VIEW [ViewName] AS
SELECT *
FROM Table1 JOIN Table2 ON Table1.AppGuid = Table2.AppGuid

并在您的实体框架模型中导入ViewName(就像您对普通 SQL 表所做的那样)并使用它来查询您需要的任何内容

编辑:查看此链接以获取更多信息http://www.mssqltips.com/sqlservertip/1990/how-to-use-sql-server-views-with-the-entity-framework/

于 2012-11-11T12:20:55.660 回答