EF code首先:映射用流利的API nontable对象流利、对象、code、EF

2023-09-03 06:33:46 作者:清风欲叶

我应该如何映射我的EF codeFirst nontable对象,如视图,StoredProcedure的等用流利的API。

How should I map my nontable objects in EF CodeFirst such as Views, StoredProcedure and etc with fluent API.

推荐答案

不支持映射到存储过程和VEW但在code第一。而这些都是一些变通的朱莉娅勒曼的编程实体框架:$ C C首先$

Mapping to store procedure and vew is not supported yet in code first. And these are some work around from Julia Lerman's Programming Entity Framework : Code First.

映射到更新的视图

modelBuilder.Entity< myEntity所>()ToTable(MY_VIEW)

查看列名应该是相同的实体字段名称和你     可以使用实体框架插入,更新和删除数据     并选择它。 只是骗$ C C $首先,告诉浏览     为表的。

View column names should be the same as Entity field name and you can use the Entity Framework to insert, update, and delete data as well as selecting it. Just lie to Code First and tell the View as Table.

使用视图来填充对象

VAR myEntity所= dbContext.MyEntity.SqlQuery(SELECT * FROM dbo.MY_VIEW)

查看列名应该是相同的实体字段名,你仍然可以得到的DbContext的功能,如更改跟踪,延迟加载。

View column names should be the same as Entity field names and you still get DbContext features such as change tracking, lazy loading.

使用视图来填充Nonmodel对象

VAR myNonModel = dbContext.Database.SqlQuery(SELECT * FROM dbo.MY_VIEW)

查看列名应该是相同的实体字段名。

View column names should be the same as Entity field names.

使用存储过程

同样的技术与视图中工作。

Same technique for working with view.

VAR myEntity所= dbContext.MyEntity.SqlQuery(dbo.StoredProcedureName @ P0 @ P1,myParam1,myParam2)