实体框架查询的服务器端执行与存储过程相结合 [英] Server-side execution of Entity Framework Query combined with Stored Procedure

查看:105
本文介绍了实体框架查询的服务器端执行与存储过程相结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能调用从一个的ObjectQuery StoredProcedure的?基本上,我想动态生成查询和执行它的服务器端。你可以想象,每个查询是一个搜索,你可以用和或或合并不同标准的一部分。这是工作的罚款
像这样创建ObjectQueries。

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...



所以,我怎么能得到这个与存储过程调用工作。问题是,调用ExecuteFunction来将返回一个ObjectResult。

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

推荐答案

我看不出有任何存储过程的代码中的电话但如果你想结合的ObjectQuery 或LINQ到实体查询与存储过程中的答案很简单:不可能的。原因是相同的SQL。你不能用结果集的SQL存储过程调用的工作。

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.

您还不能定义的ObjectQuery / LINQ到-entities查询作为存储过程。

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

这篇关于实体框架查询的服务器端执行与存储过程相结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆