我的資料服務有IQueryable型別的方法,我的控制器正試圖轉換日期時間,但我得到這個錯誤。任何幫助將是巨大的。
錯誤
方法'System.String ToCommonDateString(System.Nullable`1[System.DateTime])'/span>不支持翻譯成SQL。
資料服務
public IQueryable< TemplatesJoinAgent> GetTemplateAgentKeyDiseaseId(Guid? agentKey, Guid? diseaseId)。
{
//common part
var TemplatesJoinAgent = (from t in UnitOfWork. GetRepository<Template>().Get(t => t.IsCurrentVersion && t.Status == (short)TemplateMode.Published)
join r in UnitOfWork.GetRepository<Regimen>().Get() on t.Id equals r.TemplateId
join rp in UnitOfWork.GetRepository<RegimenPart>().Get() on r.Id equals rp.RegimenId
join re in UnitOfWork.GetRepository<RegimenEntry>().Get() on rp.Id equals re.RegimenPartId
join a in UnitOfWork.GetRepository<Agent>().Get() on re.AgentVersionKey equals a.VersionKey
select new TemplatesJoinAgent
{
TemplateId = t.TemplateId,
TemplateTitle = t.Title,
GroupTitle = t.GroupTitle,
GuideLineTitle = t.GuideLineTitle,
ExternalDiseaseId = t.ExternalDiseaseId,
DiseaseName = t.DiseaseName,
VersionKey = t.VersionKey,
AgentRxNormTallMan = a.RxNormTallMan,
AgentNccnTallMan = a.NccnTallMan,
AgentName = a.Name,
AgentVersionKey = a.VersionKey,
Added = t.Added,
Modified = t.Modified,
Indication = t.Indications,
});
TemplatesJoinAgent = TemplatesJoinAgent.Distinct()。
return TemplatesJoin
}
controller
PublishedDate = (t.Modified ? ? t.Added).ToCommonDateString(),
public static string ToCommonDateString(this DateTime? d)
{
return (d.HasValue ? d.Value.ToCommonDateString() : "N/A") 。
uj5u.com熱心網友回復:
引擎不知道如何將你的自定義函式翻譯成SQL。最簡單的方法是在使用自定義函式的投影前添加一個AsEnumerable()來解決這個問題。這就將背景關系從 SQL 變成了記憶體中,并允許自定義函式。
風險在于,您需要確保在呼叫 AsEnumerable() 之前,您已經盡可能多地執行了您的過濾器,否則您將拉回比您需要的更多的資料并在記憶體中進行過濾。當然,如果你的過濾器需要自定義函式,那么你將不得不接受這一點,或者改變你的過濾器以兼容SQL。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/306662.html
標籤:
下一篇:本地主機上的PHP檔案禁止訪問
