首先使用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:
答案 0 :(得分:0)
您可以使用这两个表之间的 JOIN 创建 VIEW 。在此之后,您可以使用EF中的视图。
在SQL中执行此操作
CREATE VIEW [ViewName] AS
SELECT *
FROM Table1 JOIN Table2 ON Table1.AppGuid = Table2.AppGuid
在您的Entity Framework模型中导入 ViewName (就像使用普通的SQL表一样)并使用它来查询您需要的任何内容
编辑:请查看此链接以获取更多信息http://www.mssqltips.com/sqlservertip/1990/how-to-use-sql-server-views-with-the-entity-framework/