次のエラーが表示されます
タイプ「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);
要求された詳細情報を尋ねる
AuditGroup クラス
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'");
}