Nhibernate和linq问题
我得到以下表达式:
_senderRepos.Get(s => s.User.Email == fromAddress);
导致
could not resolve property: User.Email of: Module.Fax2Pdf.MailToFax.Models.Sender
类:
public class Sender
{
public virtual int Id { get; set; }
public virtual Site Site { get; set; }
public virtual User User { get; set; }
}
映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="Module.Fax2Pdf.MailToFax.Models.Sender, Module.Fax2Pdf" table="fax_allowed_senders">
<id name="Id" column="id">
<generator class="sequence">
<param name="sequence">fax_allowed_senders_id_seq</param>
</generator>
</id>
<many-to-one column="site_id" name="Site" />
<many-to-one column="user_id" name="User" />
</class>
</hibernate-mapping>
并且用户类在其映射文件中确实有一个电子邮件属性。我做错了什么?
更新、用户映射
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false">
<class name="Gate.Users.User, Gate.Models" table="users">
<id name="Id" column="id">
<generator class="sequence">
<param name="sequence">users_id_seq</param>
</generator>
</id>
<many-to-one column="site_id" name="Site" />
<property name="FirstName" column="first_name" type="String" length="30"/>
<property name="LastName" column="last_name" type="String" length="30"/>
<property name="CanDelete" column="can_delete" type="boolean" />
<property name="Email" column="email" type="String" length="255"/>
<property name="Department" column="department" type="String" length="30"/>
<property name="Title" column="title" type="String" length="30"/>
<many-to-one class="Gate.Extensions.Extension, Gate.Models" column="extension_id" name="Extension" />
<property name="Status" column="status" type="integer" />
<property name="CreatedAt" column="created_at" />
<property name="UpdatedAt" column="updated_at" />
<property name="TimeZone" column="timezone" type="integer" />
<property name="MiddleNames" column="middle_names" type="string" />
<property name="NamePrefix" column="name_prefix" type="string" />
<property name="NameSuffix" column="name_suffix" type="string" />
<property name="DateOfBirth" column="dob" />
<property name="RemovedAt" column="removed_at" />
<property name="ProxyMedia" column="proxy_media" type="boolean" />
</class>
</hibernate-mapping>
I get the following expression:
_senderRepos.Get(s => s.User.Email == fromAddress);
which results in
could not resolve property: User.Email of: Module.Fax2Pdf.MailToFax.Models.Sender
class:
public class Sender
{
public virtual int Id { get; set; }
public virtual Site Site { get; set; }
public virtual User User { get; set; }
}
mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="Module.Fax2Pdf.MailToFax.Models.Sender, Module.Fax2Pdf" table="fax_allowed_senders">
<id name="Id" column="id">
<generator class="sequence">
<param name="sequence">fax_allowed_senders_id_seq</param>
</generator>
</id>
<many-to-one column="site_id" name="Site" />
<many-to-one column="user_id" name="User" />
</class>
</hibernate-mapping>
And the User class DO have a Email property in it's mapping file. What am I doing wrong?
Update, user mapping
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false">
<class name="Gate.Users.User, Gate.Models" table="users">
<id name="Id" column="id">
<generator class="sequence">
<param name="sequence">users_id_seq</param>
</generator>
</id>
<many-to-one column="site_id" name="Site" />
<property name="FirstName" column="first_name" type="String" length="30"/>
<property name="LastName" column="last_name" type="String" length="30"/>
<property name="CanDelete" column="can_delete" type="boolean" />
<property name="Email" column="email" type="String" length="255"/>
<property name="Department" column="department" type="String" length="30"/>
<property name="Title" column="title" type="String" length="30"/>
<many-to-one class="Gate.Extensions.Extension, Gate.Models" column="extension_id" name="Extension" />
<property name="Status" column="status" type="integer" />
<property name="CreatedAt" column="created_at" />
<property name="UpdatedAt" column="updated_at" />
<property name="TimeZone" column="timezone" type="integer" />
<property name="MiddleNames" column="middle_names" type="string" />
<property name="NamePrefix" column="name_prefix" type="string" />
<property name="NameSuffix" column="name_suffix" type="string" />
<property name="DateOfBirth" column="dob" />
<property name="RemovedAt" column="removed_at" />
<property name="ProxyMedia" column="proxy_media" type="boolean" />
</class>
</hibernate-mapping>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您首先在
IQueryable
上调用.Expand()
会怎样?因此,假设您有一个会话,它可能如下所示:
不幸的是,这需要您导入 NHibernate 扩展方法。
What if you called
.Expand()
on yourIQueryable
first?So, assuming you had a session, it might look like this:
Unfortunately that requires you to import an NHibernate extension method.
抱歉。我在存储库中的
Get
方法上使用QueryOver
,并在其他所有内容上使用Query
。当我切换到查询
时它起作用了。Apologies. I was using
QueryOver
on theGet
method in the Repository andQuery
for everything else. It works when I switched toQuery
.