简体   繁体   中英

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.

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.

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.

Question: Is there a way to use a select stored procedure as it is done for insert/update/delete and continue using 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?

The second question is quite common, especially in enterprise scenarios where you have security concerns and serious DBAs (!). 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. 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. 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. The relevant SO article is here , and it links to a nice article here , which should help you.

EDIT :

One more option is to add a defining query to control how EF performs the select. See here .

Nick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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