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

本文关键字:存储过程 起来 连接 参数 LINQ | 更新日期: 2023-09-27 18:21:35

我试过这个

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_Field]sp_Get_log(System.String)'方法,并且此方法无法转换为存储表达式。

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

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

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
};