存储程序和EF代码优先 [英] Stored Procedures and EF Code First

查看:128
本文介绍了存储程序和EF代码优先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用存储过程从数据库中检索实体,我不在乎跟踪更改。我只需要解决所有实体,包括相关的实体。

I would like to use a stored procedure to retrieve entities from a DB, I don't care about tracking changes. I just need all entities be resolved including related ones.


  1. 我必须使用SqlCommand吗?

  1. Do I have to use SqlCommand?

复杂属性如何解决?

你可以告诉我吗?

谢谢!

推荐答案

关于在EF中使用存储过程的一般答案是,所以纯EF中的存储过程将不会处理导航属性。答案还提到了 EFExtensions ,但在DbContext API中不可用。

General answer about using stored procedures in EF is here so stored procedure in pure EF will not handle navigation properties. The answer also mentioned EFExtensions but that is not available in DbContext API.

要在DbContext API中执行存储过程,请使用:

To execute stored procedure in DbContext API use:

var entities = context.Database.SqlQuery<MyEntity>(...);

DbContext API不提供任何类似EDMX和ObjectContext API的功能导入。

DbContext API doesn't offer any function import like EDMX and ObjectContext API.

这篇关于存储程序和EF代码优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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