Nhibernate和linq问题

发布于 2024-10-10 20:21:54 字数 2833 浏览 5 评论 0原文

我得到以下表达式:

_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缪败 2024-10-17 20:21:54

如果您首先在 IQueryable 上调用 .Expand() 会怎样?

因此,假设您有一个会话,它可能如下所示:

var senders = 
    (from sender in session.Query<Sender>().Expand("User")
     where sender.User.Email == fromAddress
     select sender);

不幸的是,这需要您导入 NHibernate 扩展方法。

What if you called .Expand() on your IQueryable first?

So, assuming you had a session, it might look like this:

var senders = 
    (from sender in session.Query<Sender>().Expand("User")
     where sender.User.Email == fromAddress
     select sender);

Unfortunately that requires you to import an NHibernate extension method.

香橙ぽ 2024-10-17 20:21:54

抱歉。我在存储库中的 Get 方法上使用 QueryOver,并在其他所有内容上使用 Query。当我切换到查询时它起作用了。

Apologies. I was using QueryOver on the Get method in the Repository and Query for everything else. It works when I switched to Query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文