引用实体的组件。没有加载

时间:2016-04-25 06:59:47

标签: nhibernate

我有以下映射,问题是EmailTemplate没有被急切加载,并且在检索用户时被设置为null。任何人都可以指导我或者推荐我一些材料。我花了很长时间搜索,没有任何事情。

用户映射

    public UserMap()
    {
        Id(x => x.Id); 
        Component(x => x.State, y =>
        {
            y.Map(x => x.Name);
            y.Map(x => x.surname);
            y.References(x => x.EmailTemplate).Not.LazyLoad();
        });
    }

编辑: EmailTemplate

    public  class EmailTemplate:Entity
    {     
        public virtual string Subject { get; set; }
        public virtual string Body { get; set; }
        public virtual ICollection<User> Users { get; set; }
    }  

EmailTemplateMap

    public EmailTemplateMap()
    {
        Id(x => x.Id);
        Map(x => x.Subject);
        Map(x => x.Body);
        HasMany(x => x.Users).Inverse();
    }

国家

    public class State : ValueObject<State>
    {
        public virtual string State { get; set; }
        public virtual EmailTemplate EmailTemplate { get; set; }
    }

用户

    public class User:Entity
    {
        public virtual string Name  { get; set; }
        public virtual string Surname { get; set; }
        public virtual State State { get; protected set; }
    }

0 个答案:

没有答案