我收到以下错误
抛出了类型'Antlr.Runtime.NoViableAltException'的异常。 [.OrderBy [ORM.Entities.Core.Message,System.DateTime的](其中[ORM.Entities.Core.Message](NHibernate.Linq.NhQueryable`1 [ORM.Entities.Core.Message] 引用((x,)=> (AndAlso(AndAlso(String.op_Equality(x.ConcerningItemType,p1), Equal(x.ConcerningItemId,p2)),OrElse(Equal(x.Sender.Id,p3), .Any [ORM.Entities.Core.MessageRecipient](x.Recipients,(r,)=> (Equal(r.Employee.Id,p4)),))))),),Quote((x,)=> (.FirstORM.Entities.Core.AuditGroup.Created)),)]
当我有一个IQueryable结果集(刚刚应用了一些逻辑)然后我尝试在调用ToList()之前通过子属性变量对它进行排序
var results = query.Where(x => x.ConcerningItemType == "1422" && x.ConcerningItemId == EnquiryId && //Messages for this Enquiry
(x.Sender.Id == EmployeeId || x.Recipients.Any(r => r.Employee.Id == EmployeeId)));
然后我尝试订购导致错误的
var results2 = results.OrderBy(x => x.AuditGroup.First().Created).ToList();
如果我执行以下操作而不是出现错误(移动tolist以强制它命中数据库)
var results3 = results.ToList().OrderBy(x => x.AuditGroup.First().Created);
询问更多信息
AuditGroup Class
public class AuditGroup : Entity
{
public virtual string Guid { get; set; }
public virtual string PageName { get; set; }
public virtual string ControlId { get; set; }
public virtual string ItemType { get; set; }
public virtual int ItemId { get; set; }
public virtual int EmployeeId { get; set; }
public virtual string IPAddress { get; set; }
public virtual string Parameters { get; set; }
public virtual DateTime Created { get; set; }
}
消息类
public class Message : Entity
{
// This class represents the standard address fields, for reuse in other entities
//
public virtual int Id { get; set; }
public virtual int ConcerningItemId { get; set; }
public virtual String ConcerningItemType { get; set; }
public virtual String Subject { get; set; }
public virtual String Body { get; set; }
public virtual int RecipientCount { get; set; }
public virtual String RowStatus { get; set; }
public virtual Employee Sender { get; set; }
public virtual ICollection<MessageRecipient> Recipients { get; set; }
//eww have to do this to be able to access the created date of the message (stored in AuditGroup... Stupidly!)
public virtual ICollection<AuditGroup> AuditGroup { get; set; }
}
消息映射
public MessageMapping()
{
Id(x => x.Id).Column("MessageId");
Map(x => x.ConcerningItemId).Nullable().Column("ItemId");
Map(x => x.ConcerningItemType).Nullable().Column("ItemType");
Map(x => x.Subject).Nullable();
Map(x => x.Body);
Map(x => x.RecipientCount).Column("MessageRecipientCount");
Map(x => x.RowStatus).Column("MessageRowStatus");
References(x => x.Sender).Column("EmployeeId");
HasMany(x => x.Recipients).KeyColumn("MessageId");
//AuditGroup has ItemId-ItemType Needs to map to MessageId-ItemType
HasMany(x => x.AuditGroup).KeyColumn("ItemId").Where("ItemType = '1419'");
}
答案 0 :(得分:0)
请提供更多信息(实体和地图)
我很确定x.AuditGroup.First().Created
应该受到责备。我说这是因为我试着想到生成的SQL查询而我不能。
我建议为AuditGroup
创建一个别名,然后按顺序排序。这非常粗略我会怎么做。
AuditGroup auditGroupAlias = null;
query.JoinAlias(p => p.AuditGroup, () => auditGroupAlias)
.OrderBy(()=>auditGroupAlias.Created)
再次提供部分信息,我只能给出部分解决方案。