我收到以下错误
引发了“Antlr.Runtime.NoViableAltException”类型的异常。[.OrderBy[ORM.Entities.Core.Message,System.DateTime](.Where[ORM.Entities.Core.Message](NHibernate.Linq.NhQueryable`1[ORM.Entities.Core.Message], Quote((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);
询问要求的更多信息
审计组类
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'");
}