当我尝试映射我的类时,我遇到了以下问题
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,但它包含prop Id,为什么我会收到此错误?谢谢 。 有人可以帮我解决问题吗?
答案 0 :(得分:0)
这是猜测,因为我总是发现FNH的默认Id处理非常令人满意,但是......
我认为你的PrimaryKeyNamePlusId类告诉FNH期望你实体中的所有ID属性都是_ID形式,但是你说你的Project实体的ID属性叫做“Id”,所以FNH找不到它
您可以通过更改项目中的属性名称来测试这一点。
public virtual Guid Project_ID { get; protected set; }
并查看错误是否消失。