当前位置: 首页 > 编程语言 > C#

nhibernate joinqueryover不相关的表(相同的外键)分享

时间:2023-04-11 11:33:26 C#

C#学习教程:nhibernatejoinqueryover不相关的表(相同的外键)我有这个问题:varresult=_session.QueryOver(()=>contentReferenceAlias).Inner.JoinAlias(()=>contentReferenceAlias.ContentReference,()=>contentLibrarySearchAlias.ContentReference).Where(()=>contentReferenceAlias.ToLanguage。Id==languageId&&contentReferenceAlias.ContentReference.Id==contentLibrarySearchAlias.ContentReference.Id).SelectList(列表=>列表.Select(()=>contentReferenceAlias.ContentReference).Select(()=>contentLibrarySearchAlias.ContentReference).Select(()=>contentReferenceAlias.ContentReference.Id).WithAlias(()=>resultAlias.ContentReferenceId).Select(()=>contentReferenceAlias.ContentReference.Id).WithAlias(()=>resultAlias.ContentReferenceId).Select(()=>contentReferenceAlias.OrderedFrom).WithAliaSQL即时尝试重新创建:SELECTA.OrderedFrom,C.LastOrdered,A.ContentReferenceId,B.TitleFROMTranslationContentReferenceAINNERJOINTranslationOrderCON(A.TranslationOrderId=C.Id)INNERJOINContentLibrarySearchBON(A.ContentReferenceId=b.ContentReferenceId)WHEREA.ToLanguageId='xxxx-xxxx-xxxx-xxxx-xxxx'如果我正确理解你的场景,你将无法为了通过QueryOverAPI实现与中间人的连接(外键引用),NHibernate需要始终知道路径,因此如果没有从TranslationContentReference到ContentReference到ContentLibrarySearch的显式映射,我们就无法创建正确的JoinAliases。所以第一个选项是扩展中间人对象publicclassContentReference{...publicvirtualIListTranslationContentReference{get;设置;}公共虚拟IListContentLibrarySearch{得到;,也就是少NHibernate多SQL,就是创建ISQLQuery以上就是C#学习教程的全部内容:nhibernatejoinqueryoverunrelatedtables(sameforeignkey),如果对大家有用需要进一步了解C#学习教程,希望大家多多关注——ISQLQueryquery=session.CreateSQLQuery("SELECTA.OrderedFrom,C.LastOrdered,A.ContentReferenceId,B.TitleFROMTranslationContentReferenceAINNERJOINTranslationOrderCON(A.TranslationOrderId=C.Id)INNERJOINContentLibrarySearchBON(A.ContentReferenceId=b.ContentReferenceId)WHEREA.ToLanguageId=:language");query.SetString("语言","xxxx-xxxx-xxxx-xxxx-xxxx");变种结果=查询。SetResultTransformer(newAliasToBeanResultTransformer(typeof(MyDTO))).List();本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: