EF 4 Stored Procedure Mixed In With LINQ
I have a proc that returns two fields as a custom class ge开发者_StackOverflow社区nerated by the EF framework (a mapped class for the custom result). Can I join the proc results in with a ADO.NET EF LINQ query? I'm getting errors that suggests no, but I'm not sure.
Thanks.
No, joining resultset from stored procedure in Linq to entities query is not possible. It is also very hard in SQL directly - I can imagine some approach with OpenQuery in TSQL but it is terrible solution.
If you really need to join result from your stored procedure with some Linq to entities query you should execute stored procedure and query separately and join them using Linq to objects. But be aware that this solution will transfer complete resultsets from both operations to your application server and join will be performed by .NET in memory.
Another solution is to rewrite your stored procedure to UDF (user defined function in TSQL). In this case you will not be able to use mapping of function result into entity but you will be able to join result of the function with other query in EQL.
The best solution in this case would probably be new stored procedure which performs the necessary join operation.
精彩评论