[英]EF Core 'The DbFunction 'ÉmpContext.fnGetEmployeeEligibility' has an invalid return type 'ÉmpMaster'' while calling table-valued function
我在 SQL Server fnGetEmployeeEligibility 中有一個表值 function 服務器fnGetEmployeeEligibility
,它接受EmpId
並根據一些計算它返回包含以下列的結果集:
EmpId
( int
)IsEligibleForPromotion
( bit
)IsEligibleForHike
( bit
)IsEligibleForRelocation
( bit
)IsEligibleForRemote
( bit
)IsEligibleForSuperWallet
( bit
)SQL function 工作正常,我已經測試過了。 現在 O 需要在我的應用程序中調用這個 function 並且我正在使用 EF Core
這是拋出一個錯誤:
DbFunction 'ÉmpContext.fnGetEmployeeEligibility' 具有無效的返回類型 'ÉmpMaster'。 確保返回類型可以被當前提供者映射'
Public void CheckEligiblity(int empId)
{
var result = _empContext.fnGetEmployeeEligibility(empId);
}
在我的EmpContext
class
[DBFunction("fnGetEmployeeEligibility","emp")]
Public EmpMaster fnGetEmployeeEligibility(int empId)
{
EmpMaster empM = new EmpMaster();
return empM;
}
我創建了一個自定義 class EmpMaster
,它具有 map function 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 中添加了對表值函數作為第一個 class 公民的支持。
表值函數可以映射到返回 IQueryable 的函數,現在可以在 linq 查詢中完全組合。
https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/whatsnew#table-valued-functions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.