c# - C# LINQ to Entities 无法识别方法 'System.String 方法,并且此方法无法转换为存储表达式
问题描述
这只是我的情况的一个例子
var query =
Employee.Join(department,
emp => emp.depId,
dep=> dep.Id,
(emp, dep) =>
new EmployeeModel{ Name = emp.Name, Total = GetTotal(emp)});
public string GetTotal(emp)
{
//dynamically decide which column to pass to the stored procedure, that is
//why I am passing the whole object
total = sp(emp.column1, emp.column2);//here I pass the parameters to SP
return total;
}
我在这里遇到了一个异常,我不知道如何解决它。任何帮助将不胜感激。谢谢
解决方案
这当然会发生。Linq to entity 不知道是什么GetTotal()
,并且考虑到它将如何为返回的每一行调用存储过程,我建议您将连接本身移动到存储过程中,暂时忘记 LINQ。
推荐阅读
- reactjs - 如何在 ReactJS 中将更改的状态从子组件传递给其父组件
- java - 与 Microsoft SQL Server 的连接中的 Java 问题
- coq - 在对列表上证明子集关系的属性
- swift - 枚举函数并在swift上用新值减去旧值
- javascript - serializeArray 函数不返回输入字段值和 tinyMCE 文本区域值
- android - 在 Android 中编辑上传到 Dropbox 的文件
- python - Python for Maya:将显示层更改为“参考”
- python - 如何检查用户输入是否在列表中,并获取其列表编号?
- ruby-on-rails - Rails 查找某人的生日
- javascript - 在javascript中定义对象时,星号大括号*{是什么意思