C# 使用linq到nhibernate时未实现该方法或操作
我正在尝试使用linq到nhibernate 3,我已经做了以下linq查询C# 使用linq到nhibernate时未实现该方法或操作,c#,linq-to-nhibernate,C#,Linq To Nhibernate,我正在尝试使用linq到nhibernate 3,我已经做了以下linq查询 var a = (from c in Session.Query<ChoiceValue>() join Specific in ( (from choicevaluelocale in Session.Query<ChoiceValueLocale>()
var a = (from c in Session.Query<ChoiceValue>()
join Specific in
(
(from choicevaluelocale in Session.Query<ChoiceValueLocale>()
where
choicevaluelocale.UICulture == "en-GB"
select new
{
choicevaluelocale.ChoiceValue.ChoiceGroup.ChoiceGroupName,
choicevaluelocale.ChoiceValue.ChoiceValueId,
choicevaluelocale.DisplayName,
choicevaluelocale.Description
}))
on new { c.ChoiceGroup.ChoiceGroupName, c.ChoiceValueId }
equals new { Specific.ChoiceGroupName, ChoiceValueId = (Int32)Specific.ChoiceValueId } into Specific_join
from Specific in Specific_join.DefaultIfEmpty()
select new
{
c.ChoiceGroup.ChoiceGroupName,
ChoiceValueId = (Int32?)c.ChoiceValueId,
SpecificValueDisplayName = Specific.DisplayName,
SpecificValueDescription = Specific.Description,
}).ToList();
堆栈跟踪是
at NHibernate.Linq.Visitors.QueryModelVisitor.VisitGroupJoinClause(GroupJoinClause
groupJoinClause, QueryModel queryModel, Int32 index)
at Remotion.Data.Linq.Clauses.GroupJoinClause.Accept(IQueryModelVisitor visitor,
QueryModel queryModel, Int32 index)
at Remotion.Data.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1
bodyClauses, QueryModel queryModel)
at Remotion.Data.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
at NHibernate.Linq.Visitors.QueryModelVisitor.GenerateHqlQuery(QueryModel
queryModel, VisitorParameters parameters, Boolean root)
at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor
sessionFactory)
有谁能帮我解决这个问题吗?在我看来,您正在使用的Linq to Hibernate库不完整。某个地方正在抛出一个
NotImplementedException
。您使用的是稳定版本吗
快速浏览一下互联网,发现不支持selects中的组联接和子查询。您在示例中使用了组联接,因此出现了异常。具体而言,以下职位:
public override void VisitGroupJoinClause(GroupJoinClause groupJoinClause, QueryModel queryModel, int index)
{
throw new NotImplementedException();
}
更新:从5.1.x版开始,NHibernate的LINQ提供程序仍然支持此操作
一些解决方案建议您编写自己的HQL(如原始SQL),而不是Linq语法。我正在使用nhibernate 3.1,它为Linq到nhibernate内置了库。该库不完整。我翻遍了源代码;
NHibernate.Linq.Visitors.QueryModelVisitor.VisitGroupJoinClause()方法没有实现,这意味着不支持组联接。您必须重新处理Join或使用直接SQL。
public override void VisitGroupJoinClause(GroupJoinClause groupJoinClause, QueryModel queryModel, int index)
{
throw new NotImplementedException();
}