我向类添加了一些计算出的只读属性,现在抛出QueryException:无法解析属性.
I added some calculated read-only properties to my class and it's now throwing a QueryException: could not resolve property.
这是我的课(现在是假计算):
Here is my class (fake calculations right now):
public class IncompleteApplication : DealerBase { public virtual string Content { get; set; } public virtual string LegalBusinessName { get { return "Leg"; } } public virtual string DbaName { get { return "Dba"; } } }映射:
public class IncompleteApplicationMap : DealerBaseMap<IncompleteApplication> { public IncompleteApplicationMap() { Schema("Dealer"); Table("XmlSerialization"); Map(app => app.Content); } }并调用代码:
data.GridDataItems = (from app in _Repository.GetAll() select new GridData.GridDataItem() { ID = app.Id, SubmittedDate = app.LastUpdated, UserName = app.User.UserName, LegalBusinessName = app.LegalBusinessName, DbaName = app.DbaName }).ToArray();_Repository.GetAll()返回一个IQueryable.当我在GetAll()之后添加.ToList()时,代码可以正常运行(尽管我遇到Select N + 1的情况).
_Repository.GetAll() returns an IQueryable. When I add a .ToList() after GetAll() the code runs just fine (although I get a Select N + 1 situation).
感谢您的帮助!
推荐答案您应将两个只读属性与nhibernate映射,并在查询时使用公式提供其值.我不太熟悉nh,但是针对您的属性的标准xml映射如下所示:
You should map your two read-only properties with nhibernate and use a formula to provide their values while querying. I don't know fluent nh very well, but a standard xml mapping for your properties would look something like:
<property name="DbaName" access="readonly" insert="false" update="false" type="String" formula="(SELECT 'Dba')" />更多推荐
使用Linq到NHibernate时,向类中添加计算的属性会引发NHibernate错误
发布评论