流畅的Nhibernate映射与列

时间:2013-05-22 09:04:28

标签: fluent-nhibernate fluent-nhibernate-mapping

嗨我在处理流利的nhibernate时遇到了一个问题。

我的用户实体位于

之下
  

公共类UserEntity
      {
          public virtual int Userid {get;组; }
          public virtual CompanyEntity CompanyId {get;组; }
          public virtual string Name {get;组; }
          public virtual string Email {get;组; }
          public virtual string用户名{get;组; }
          public virtual string Password {get;设置;}
          public virtual decimal MinLimit {get;设置;}
          public virtual decimal MaxLimit {get;设置;}
          public virtual DateTime Birthdate {get;设置;}
          public virtual RoleEntity Roleid {get;组; }
         public virtual int CreatedBy {get;设置;}
          public virtual DateTime CreatedDate {get;设置;}
          public virtual bool Active {get;设置;}
      }
  }

和映射类如下

  

公共类UserMap:ClassMap
          {
              public UserMap()
              {
                  Id(x => x.Userid);
                  参考文献(x => x.CompanyId).Column(“CompanyId”)。Cascade.All();
                  地图(x => x.Name);
                  地图(x => x.Email);
                  地图(x => x.Username);
                  地图(x => x.Password);
                  地图(x => x.MinLimit);
                  Map(x => x.MaxLimit);
                  地图(x => x.Birthdate);
                  参考文献(x => x.Roleid).Column(“Roleid”)。Cascade.All();
                  地图(x => x.CreatedBy);
                  地图(x => x.CreatedDate);
                  地图(x => x.Active);
                  表( “向tblUsers”);
              }
          }

现在,当我尝试执行我的程序时,它会给我一些错误。

  

无法确定以下类型:ProductPO.Models.Entites.UserEntity,ProductPO,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null,对于列:NHibernate.Mapping.Column(CreatedBy)

我的帮助程序类如下

  

private static ISessionFactory _sessionFactory;

    private static ISessionFactory sessionFactory  
    {  
        get  
        {  
            if (_sessionFactory == null)  
            {  
                initialisationFactory();  
            }  

            return _sessionFactory;  
        }  

    }  
    private static void initialisationFactory()  
    {  
        try  
        {  

            _sessionFactory = Fluently.Configure()  
                            .Database(MsSqlConfiguration.MsSql2005.ConnectionString(@"Server=10.10.10.10;Database=Product;uid=sa;pwd=12345;Trusted_Connection=false;").ShowSql())    
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<CompanyEntity>().ExportTo("d:\\"))  
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ModuleEntity>().ExportTo("d:\\"))    
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<RoleEntity>().ExportTo("d:\\"))  
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserEntity>().ExportTo("d:\\"))  
                            .ExposeConfiguration(cfg => new SchemaExport(cfg))  
                            .BuildSessionFactory();  
        }  
        catch (Exception e)  
        {  

            throw;  
        } 
    }  
    public static ISession OpenSession()  
    {  
        return sessionFactory.OpenSession();  
    }  

提前致谢

2 个答案:

答案 0 :(得分:0)

不确定这是否能解决问题,但您的映射类应该将模型类型传递给基类,如下所示:

public class UserMap : ClassMap<UserEntity>

CreatedBy列是否也存在于基础表中?

如果有内部异常,你可以发布内部异常....

答案 1 :(得分:0)

最可能的原因是设置UserEntity 的程序集与用户地图定义的不一样。

配置映射:

Fluently.Configure() 
    .Database(MsSqlConfiguration.MsSql2005.ConnectionString("{OMITED}").ShowSql()) 
    .Mappings(m => {
        AddFromAssemblyOf<UserMap>()
    })  
    .ExposeConfiguration( c => 
        new SchemaExport(c)
        .Execute(false, true, false) 
    )

无需添加一对一映射。这样,Fluent NHibernate搜索从ClassMap继承的整个集合类