【发布时间】:2020-07-14 12:41:20
【问题描述】:
我在 SQL Server fnGetEmployeeEligibility 中有一个表值函数,它接受 EmpId,并根据一些计算返回一个包含这些列的结果集:
-
EmpId(int) -
IsEligibleForPromotion(bit) -
IsEligibleForHike(bit) -
IsEligibleForRelocation(bit) -
IsEligibleForRemote(bit) -
IsEligibleForSuperWallet(bit)
SQL 函数工作正常,我已经对其进行了测试。现在 O 需要在我的应用程序中调用这个函数,我正在使用 EF Core
这是抛出一个错误:
DbFunction“ÉmpContext.fnGetEmployeeEligibility”的返回类型“ÉmpMaster”无效。确保返回类型可以被当前提供者映射到'
Public void CheckEligiblity(int empId)
{
var result = _empContext.fnGetEmployeeEligibility(empId);
}
在我的EmpContext 课堂上
[DBFunction("fnGetEmployeeEligibility","emp")]
Public EmpMaster fnGetEmployeeEligibility(int empId)
{
EmpMaster empM = new EmpMaster();
return empM;
}
我创建了一个自定义类 EmpMaster,它具有映射函数 fnGetEmployeeEligibility 的属性:
Public Class EmpMaster
{
Public int EmpId { get; set; }
Public bool IsEligibleForPromotion { get; set; }
Public bool IsEligibleForHike { get; set; }
Public bool IsEligibleForRelocation { get; set; }
Public bool IsEligibleForRemote { get; set; }
Public bool IsEligibleForSuperWallet { get; set; }
}
【问题讨论】:
标签: c# sql-server entity-framework-core user-defined-functions