EF Core 'The DbFunction 'ÉmpContext.fnGetEmployeeEligibility' 在调用表值函数时具有无效的返回类型 'ÉmpMaster



我在SQL ServerfnGetEmployeeEligibility中有一个表值函数,它接受EmpId,并根据一些计算返回一个包含以下列的结果集:

  • EmpId(int(
  • IsEligibleForPromotion(bit(
  • IsEligibleForHike(bit(
  • IsEligibleForRelocation(bit(
  • IsEligibleForRemote(bit(
  • IsEligibleForSuperWallet(bit(

SQL函数运行良好,我已经测试过了。现在O需要在我的应用程序中调用这个函数,我正在使用EF Core

这引发了一个错误:

DbFunction"ÉmpContext.fnGetEmployeeQualification"的返回类型"É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; }
}
EF Core 5.0中增加了对表值函数作为第一类公民的支持。

表值函数可以映射到返回IQueryable的函数,现在可以在linq查询中完全组合。

https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/whatsnew#table-值函数

最新更新