Adding calculated properties to class throws NHibernate error when using Linq to NHibernate

旧时模样 提交于 2019-12-05 20:45:54

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')" />

nHibernate is generating a sql statement to execute on the server. Calculated fields don't exist in the db so you can't use them in your nHibernate query.

What you can do is execute the query to that meets all your criteria except those calculate fields, then after .ToArray() using linq on those object.

data.GridDataItems = (from app in _Repository.GetAll()
                                  select new GridData.GridDataItem()
                                  {
                                      ID = app.Id,
                                      SubmittedDate = app.LastUpdated,
                                      UserName = app.User.UserName,
                                  }).ToArray().Where(i=> i.LegalBusinessName = app.LegalBusinessName && i.DbaName = app.DbaName);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!