2012-02-09 43 views
1

我有以下问题,当我试图在我的类映射流利地图ID

Stack trace: 
Inner exception message: could not resolve property: Project_ID of: Messenia.Data.Models.Project 

这里是我的配置

private StaticHibernate() { 
      new NHibernate.ByteCode.Castle.ProxyFactoryFactory(); 
      SessionFactory = Fluently.Configure() 
       .Database (MySQLConfiguration.Standard 
       .ConnectionString ("database=messenia;server=localhost;uid=root;pwd=root")) 
       .ExposeConfiguration (c => c.Properties.Add ("hbm2ddl.keywords", "none")) 
       .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Entity>(new EntityAutoMappingConfiguration()) 

                     .IgnoreBase<Entity>() 
                     .UseOverridesFromAssemblyOf<Entity>() 
                     .Conventions.Add(typeof(PrimaryKeyNamePlusId))))                  .BuildSessionFactory(); 

和:

public class EntityAutoMappingConfiguration : DefaultAutomappingConfiguration 
    { 
     public override bool ShouldMap(Type type) 
     { 
      return type.GetInterfaces().Contains(typeof(IPersistable)); 
     } 


    } 

和:

public class PrimaryKeyNamePlusId : IIdConvention 
    { 
     public void Apply(IIdentityInstance instance) 
     { 
      instance.Column(instance.EntityType.Name + "_ID"); 
     } 
    } 

类项目不包含属性Project_Id,但它包含支持ID,所以为什么我得到这个错误?谢谢 。 有人可以帮我解决这个问题吗?

回答

0

这是一种猜测,因为我总是发现FNH的默认ID的处理方式是完全满意的,但是......

我觉得你PrimaryKeyNamePlusId类告诉FNH期待您的实体所有的ID属性为_ID形式,但是你说你的Project实体的ID属性被称为“Id”,所以FNH找不到它。

您可以通过在Project中更改属性名称来测试

public virtual Guid Project_ID { get; protected set; } 

并查看错误是否消失。