简体   繁体   English

如何在EF4中为SELECT调用存储过程以填充EntityDataSource

[英]How to call a stored Procedure for SELECT in EF4 to populate an EntityDataSource

I was trying to investigate the use of EF4 for my project and I faced this "interesting" problem. 我试图调查EF4在我的项目中的使用,但遇到了这个“有趣”的问题。

Creating the edmx, there is an easy way to connect the entities to a user interface component (DevExpress GridView for instance) passing through the EntityDataSource. 创建edmx时,有一种简单的方法可以将实体连接到通过EntityDataSource的用户界面组件(例如,DevExpress GridView)。

Question: Do you think is there a better way to bind my entities to controls? 问题: 您认为将实体绑定到控件有更好的方法吗?

Now as a client specification I would be happy to interact with the database through stored procedures (for update, insert, select, delete) limiting then the power of EF, but still it would give me some benefits. 现在,作为客户端规范,我很乐意通过限制EF功能的存储过程(用于更新,插入,选择,删除)与数据库进行交互,但是仍然可以给我带来一些好处。

Question: Is there a way to use a select stored procedure as it is done for insert/update/delete and continue using EntityDataSource? 问题: 有没有办法使用选择存储过程来完成插入/更新/删除并继续使用EntityDataSource?

Question: Do you think it is a reasonable solution to populate the entities with database views in order to pilot the select and use the stored procedure mapping otherwise? 问题: 您认为用数据库视图填充实体以引导选择并以其他方式使用存储过程映射是一种合理的解决方案吗?

Thank you for your help and thoughts. 感谢您的帮助和想法。

The first question is somewhat open in nautre, and rather dependent on the controls you are using, and the design pattern (if any) that you are trying to adhere to. 第一个问题有些悬而未决,而是取决于您使用的控件以及您要遵循的设计模式(如果有)。 From a development perspective, if you are Unit Testing you should always consider seperation of concerns, and how tightly you want to bind your controls to your 'domain'. 从开发的角度来看,如果您正在进行单元测试,则应始终考虑关注点的分离,以及将控件绑定到“域”的紧密程度。 Is this an ASP.NET application? 这是一个ASP.NET应用程序吗?

The second question is quite common, especially in enterprise scenarios where you have security concerns and serious DBAs (!). 第二个问题很常见,尤其是在您存在安全性问题和严重的DBA(!)的企业方案中。 You CAN implement select stored procedures. 您可以实现选择的存储过程。 I'd suggest reading the post found here . 我建议阅读这里找到的帖子。

As for the third question, again it is possible to use views in Entity Framework. 关于第三个问题,同样可以在实体框架中使用视图。 There are several articles and pitfalls, I'd certainly check this article first as well. 有几篇文章和陷阱,我当然也要先阅读这篇文章

2 and 3 really come down to the clients requirements. 2和3确实可以满足客户的要求。 On my current project, we are using stored procedures for create, update and delete operations, whilst allowing direct select access on our tables as necessary. 在我当前的项目中,我们使用存储过程来创建,更新和删除操作,同时允许根据需要直接选择对表的访问。 This is effective as it allows you to use the native power of EF and LINQ in terms of dynamic queries. 这是有效的,因为它允许您在动态查询方面使用EF和LINQ的本机功能。 Again, this suits our requirements, but may not suit yours! 同样,这符合我们的要求,但可能不符合您的要求!

EDIT : 编辑

I just wanted to provide a couple more links regarding your last comment, as they deal more explicitly with EntityDataSource. 我只想提供更多有关您的最后评论的链接,因为它们与EntityDataSource的关系更加明确。 The relevant SO article is here , and it links to a nice article here , which should help you. 有关SO的文章在这里 ,并且链接到这里的不错的文章,这对您有帮助。

EDIT : 编辑

One more option is to add a defining query to control how EF performs the select. 另一种选择是添加定义查询以控制EF如何执行选择。 See here . 这里

Nick. 缺口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM