Fluent Nhibernate:无法解析属性

发布于 2024-08-21 14:25:45 字数 2957 浏览 4 评论 0原文

我在使用 Fluent Nhibernate 时遇到问题:错误是“无法解析 MailHeader 类的属性 MailHeader。

问题与实体“MailHeader”内的集合有关,如果我删除集合,异常就会消失,但我想要这些集合! 提前致谢。

涉及的实体有:

    public class MailHeader : Entity
{
    public MailHeader()
    {
        MailRecipientUsers = new List<MailRecipientUser>();
        MailsDeleted = new List<MailDeleted>();

    }

    [Required]
    public virtual string Subject { get; set; }
    public virtual IList<MailRecipientUser> MailRecipientUsers { get; protected set; }
    public virtual IList<MailDeleted> MailsDeleted { get; protected set; }

}

 public class Mail : Entity
{
    public Mail()
    {
        Creation = DateTime.Now;
        MailHeader = new MailHeader();
    }

    [Required]
    public virtual string BodyText { get; set; }
    [Required]
    public virtual MailHeader MailHeader { get; set; }

    public virtual Mail Parent { get; set; }

    [Required]
    public virtual User From { get; set; }


    public virtual Mail Child { get; set; }

    [DataType(DataType.Date)]
    public virtual DateTime Creation { get; set; }
    //[Required]
    //public virtual MailType MailType { get; set; }
}

 public class MailRecipientUser : Entity
{
    [Required, DomainSignature]
    public virtual MailHeader MailHeader { get; set; }

    [Required, DomainSignature]
    public virtual User User { get; set; }

}
public class MailDeleted : Entity
{
    public MailDeleted()
    {
    }

    [DomainSignature,Required]
    public virtual MailHeader MailHeader { get; set; }
    [DomainSignature, Required]
    public virtual User User { get; set; }

}

映射:

public class MailHeaderMap : IAutoMappingOverride<MailHeader>
{
    public void Override(AutoMap<MailHeader> mapping)
    {
        mapping.HasMany(x => x.MailRecipientUsers)
            .Inverse()
            .Cascade.AllDeleteOrphan();

        mapping.HasMany(x => x.MailsDeleted)
            .Inverse()
            .Cascade.AllDeleteOrphan();

    }
}

 public class MailMap : IAutoMappingOverride<Mail>
{
    public void Override(AutoMap<Mail> mapping)
    {
        mapping.References(x => x.From);
        mapping.References(x => x.Parent);
        mapping.References(x => x.MailHeader);

        mapping.HasOne(e => e.Child)
            .WithForeignKey()
            .PropertyRef(a => a.Parent)
            .Cascade.All();
    }
}
public class MailRecipientUserMap : IAutoMappingOverride<MailRecipientUser>
{
    public void Override(AutoMap<MailRecipientUser> mapping)
    {
        mapping.References(x => x.MailHeader);
        mapping.References(x => x.User);
    }
}
public class MailDeletedMap : IAutoMappingOverride<MailDeleted>
{
    public void Override(AutoMap<MailDeleted> mapping)
    {
        mapping.References(x => x.MailHeader);
        mapping.References(x => x.User);
    }
}

I have a problem with Fluent Nhibernate: the error is "Could not resolve Property MailHeader of class MailHeader.

The problem is related to the collections inside the entity "MailHeader", if i remove the collections the exception disappear, but i want these collections!
Thank's in advance.

The Entities involved are:

    public class MailHeader : Entity
{
    public MailHeader()
    {
        MailRecipientUsers = new List<MailRecipientUser>();
        MailsDeleted = new List<MailDeleted>();

    }

    [Required]
    public virtual string Subject { get; set; }
    public virtual IList<MailRecipientUser> MailRecipientUsers { get; protected set; }
    public virtual IList<MailDeleted> MailsDeleted { get; protected set; }

}

 public class Mail : Entity
{
    public Mail()
    {
        Creation = DateTime.Now;
        MailHeader = new MailHeader();
    }

    [Required]
    public virtual string BodyText { get; set; }
    [Required]
    public virtual MailHeader MailHeader { get; set; }

    public virtual Mail Parent { get; set; }

    [Required]
    public virtual User From { get; set; }


    public virtual Mail Child { get; set; }

    [DataType(DataType.Date)]
    public virtual DateTime Creation { get; set; }
    //[Required]
    //public virtual MailType MailType { get; set; }
}

 public class MailRecipientUser : Entity
{
    [Required, DomainSignature]
    public virtual MailHeader MailHeader { get; set; }

    [Required, DomainSignature]
    public virtual User User { get; set; }

}
public class MailDeleted : Entity
{
    public MailDeleted()
    {
    }

    [DomainSignature,Required]
    public virtual MailHeader MailHeader { get; set; }
    [DomainSignature, Required]
    public virtual User User { get; set; }

}

The mapping:

public class MailHeaderMap : IAutoMappingOverride<MailHeader>
{
    public void Override(AutoMap<MailHeader> mapping)
    {
        mapping.HasMany(x => x.MailRecipientUsers)
            .Inverse()
            .Cascade.AllDeleteOrphan();

        mapping.HasMany(x => x.MailsDeleted)
            .Inverse()
            .Cascade.AllDeleteOrphan();

    }
}

 public class MailMap : IAutoMappingOverride<Mail>
{
    public void Override(AutoMap<Mail> mapping)
    {
        mapping.References(x => x.From);
        mapping.References(x => x.Parent);
        mapping.References(x => x.MailHeader);

        mapping.HasOne(e => e.Child)
            .WithForeignKey()
            .PropertyRef(a => a.Parent)
            .Cascade.All();
    }
}
public class MailRecipientUserMap : IAutoMappingOverride<MailRecipientUser>
{
    public void Override(AutoMap<MailRecipientUser> mapping)
    {
        mapping.References(x => x.MailHeader);
        mapping.References(x => x.User);
    }
}
public class MailDeletedMap : IAutoMappingOverride<MailDeleted>
{
    public void Override(AutoMap<MailDeleted> mapping)
    {
        mapping.References(x => x.MailHeader);
        mapping.References(x => x.User);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

枯叶蝶 2024-08-28 14:25:45

尝试在 MailHeader 上再次公开设置器。

Try making the setters public again on MailHeader.

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