简体   繁体   中英

Entity Framework 4, Stored Procedure for searching

i'm learning EF4 and would like someone to recommend the best practice on how to search for entities using complex criteria in a stored procedure and return entities and their navigation properties.

So lets say i have a table for Customer and a table for Contact. A customer can have many contacts. The customer table contains the CustomerID and Company name, while the Contact table contains the name and email address. This is an over simplification of what there actually is and in fact i need to keep using a storedprocedure for the search as it is also doing an approximate string matching.

the SP returns the customer columns only and includes a column to indicate the score of each search result.

the question is, how would i capture the result into the Customer Entity while still capturing the score?

Also, is there a way to load the contacts (which is a navigation property of the customer entity) in the same call? and if possible in case when the search is by email address it returns the customer but with only the contact with that email address?

In my opinion it's the wrong approach to get the data from a stored procedure while working with EF, you will loose all the flexibility that comes with EF and the thing you don't want to do with EF is write SQL Queries.

For some samples how to load contact etc. you will find here http://code.msdn.microsoft.com/ef4

同时我在这里得到了答案

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