Server-side execution of Entity Framework Query combined with Stored Procedure

旧城冷巷雨未停 提交于 2019-12-12 10:21:54

问题


Is it possible to call a StoredProcedure from an ObjectQuery? Basically I want to dynamically build a query and execute it server-side. You can imagine each query to be part of a search where you can combine different criteria with "and" or "or". It is working fine with ObjectQueries created like this.

var query1 = from a in objectContext.Articles
where a.Name = 'SOMETHING'
select new ResultType { ArticleId = a.ArticleId, Name = a.Name };

var query2 = from a in objectContext.Articles
where a.Name = 'SOMETHING ELSE'
select new ResultType { ArticleId = a.ArticleId, Name = a.Name };

query1 = query1.Intersect(query2); // or union depending on what we need

// ... and more queries

var something = query1.ToList(); // query execution...

So how I can get this working with a stored procedure call. The problem is that the call to ExecuteFunction will return an ObjectResult.


回答1:


I don't see any stored procedure call in your code but if you want to combine ObjectQuery or Linq-to-entities query with stored procedure the answer is simple: not possible. The reason is same as in SQL. You cannot work with result set of stored procedure call in SQL.

You also cannot define ObjectQuery / Linq-to-entities query as stored procedure.



来源:https://stackoverflow.com/questions/8891647/server-side-execution-of-entity-framework-query-combined-with-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!