开发者

Entity Framework 4, Stored Procedure for searching

开发者 https://www.devze.com 2023-01-05 01:37 出处:网络
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 navig开发者_Go百科ation

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 navig开发者_Go百科ation 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


in the meantime i got an answer in here

0

精彩评论

暂无评论...
验证码 换一张
取 消