使用Linq到NHibernate时,向类中添加计算的属性会引发NHibernate错误

编程入门 行业动态 更新时间:2024-10-26 00:19:06
本文介绍了使用Linq到NHibernate时,向类中添加计算的属性会引发NHibernate错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我向类添加了一些计算出的只读属性,现在抛出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错误

本文发布于:2023-05-26 16:21:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/265225.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类中   属性   错误   Linq   NHibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!