gpt4 book ai didi

linq - Nhibernate 和 linq 问题

转载 作者:行者123 更新时间:2023-12-01 05:42:34 24 4
gpt4 key购买 nike

我得到以下表达式:

_senderRepos.Get(s => s.User.Email == fromAddress);

这导致
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; }
}

映射:
<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>

并且 User 类在它的映射文件中有一个 Email 属性。我究竟做错了什么?

更新,用户映射
    <?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>

最佳答案

如果您调用 .Expand() 怎么办?在您的 IQueryable 上第一的?

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

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

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

关于linq - Nhibernate 和 linq 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4616972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com