如何在LINQ c#中将参数化存储过程与表连接

时间:2014-09-12 10:11:17

标签: c# linq stored-procedures join

我试过这个

var Result = from a in db.ViewEntity // view 
let b = db.sp_Get_log(a.id) // parametrized stored procedure  returns rowset 
select new LogFields
{
   UniqueID = a.ID,
   WorkFlow_Status = a.Document_Status,
   Creator = a.Creator,
   Duration = a.Duration,
   Approver = b.LastOrDefault().Action_User // this
};

但是我收到了这个错误,请帮助。

  

LINQ to Entities无法识别方法System.Data.Objects.ObjectResult1 [db.Agent.sp_Get_log_Fields] sp_Get_log(System.String)'方法,并且此方法无法转换为存储表达式。

1 个答案:

答案 0 :(得分:1)

首先在内存中获取结果然后以这种方式调用存储过程:

var ResultList = db.ViewEntity.ToList();

var Result =  from a in ResultList 
let b = db.sp_Get_log(a.id) // parametrized store procedure returns rowset 
select new LogFields
{
   UniqueID = a.ID,
   WorkFlow_Status = a.Document_Status,
   Creator = a.Creator,
   Duration = a.Duration,
   Approver = b.LastOrDefault().Action_User // this
};