制图选择存储在实体框架程序 [英] Mapping select stored procedures in entity framework

查看:159
本文介绍了制图选择存储在实体框架程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的方案
我使用Visual Studio 2010的实体框架4.1
我有许多表和许多存储过程的旧的数据库。
我正在写使用ASP.NET C#程序MVC 3

My scenario I'm using Visual Studio 2010 with Entity Framework 4.1 I have a legacy database with many tables and many stored procedures. I'm writing an ASP.NET C# program using MVC 3

我已经通过了数据库第一个使用ADO.NET的DbContext设计让我有所有的模型和协会及导航属性很好地建立了一个EDMX。
我可以映射插入,更新,删除程序,相关机型。
我用功能导入导入其他存储过程。
但是,我无法找到一个方法来映射我的选择程序来选择动作(由ID,选择列表,通过过滤器等选择选择)。

I have adopted the 'database first' design using ADO.NET DbContext so I have an edmx with all the models and associations and navigation properties nicely set up. I can map the insert, update, delete procedures to the relevant models. I've used 'Function Import' to import other stored procedures. However, I can't find a way to map my Select procedures to select actions (select by id, select list, select by filter etc).

EF似乎使用延迟加载所以我希望发生的是,当一个对象获取其子对象,它使用已经写好的存储过程。
(该选择程序考虑到一个请将isDeleted'标志,并使用了ORDER BY子句,除其他外)

EF seems to use lazy loading so what I want to happen is when an object fetches its child objects it uses the stored procedures already written. (The select procedures take into account an 'IsDeleted' flag, and use the 'ORDER BY' clause, amongst others)

我从这篇文章看
<一href=\"http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx\">http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
该LINQ到SQL可以拖动和SP,这听起来或多或少,正是我想要的。

I see from this article http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx that Linq to SQL allows drag and drop of SPs, which sounds, more or less, exactly what I want.

我也碰到过这个词DefiningQuery。
<一href=\"http://msdn.microsoft.com/en-us/library/cc982038.aspx\">http://msdn.microsoft.com/en-us/library/cc982038.aspx
这是我想要的吗?我不喜欢记的存储模型所做的任何更改,包括定义查询,将被覆盖,当您运行更新模型向导。

I've also come across the term DefiningQuery. http://msdn.microsoft.com/en-us/library/cc982038.aspx Is this what I want? I don't like the note 'Any changes made to the storage model, including defining queries, will be overwritten when you run the Update Model Wizard.'

总之,我希望发生的是,当一个对象获取其子对象,它使用我的存储过程。

In summary, what I want to happen is when an object fetches its child objects it uses my stored procedures.

我可以实现使用实体框架我的目标?
我错过了一些东西明显?

Can I achieve my goal using Entity Framework? Have I missed something obvious?

或者我应该尽量做到真正聪明和修改数据库实体T4模板,这样一来,例如,我的地址生成模式有此属性:

Or should I try to be really clever and modify the db Entity T4 template, so that, for example, my generated Address model has this property:

public virtual ICollection<AddressLine> AddressLines { 
    get{
        DBWrapper _db = new DBWrapper();
        return _db.GetAddressLines(AddressID);
    } 
    set{}; 
}

其中GetAddressLines是调用一个函数输入并执行neccessary转换自定义函数。

where GetAddressLines is custom function that calls a function import and does the neccessary conversions.

推荐答案

这是不可能的。你可以导入你的存储过程作为函数的进口和手动执行它们,但你不能取代EF与自定义存储过程生成的查询。

It is not possible. You can import your stored procedures as function imports and manually execute them but you cannot replace queries generated by EF with custom stored procedures.

这篇关于制图选择存储在实体框架程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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