gpt4 book ai didi

fluent-nhibernate - Fluent nHibernate Automapping 不创建复数表名

转载 作者:行者123 更新时间:2023-12-04 07:42:57 41 4
gpt4 key购买 nike

我有两张 table ,地点和设施

他们映射到两个类,

public Location : Entity
{
//properties
}

public Facility : Entity
{
public virtual Location Location { get; set; }
}

一切正常,直到我把设施改成这个
public Facility : Location
{

}

现在我从 nHibernate 得到一个异常(exception)说
NHibernate.ADOException was unhandled by user code
Message=could not execute query
InnerException: System.Data.SqlClient.SqlException
Message=Invalid object name 'Facility'.

出于某种原因,它没有将表的复数名称创建到 sql 字符串中。

谢谢你的帮助!

编辑

这是我当前的 TableNameConvention
public class TableNameConvention : IClassConvention
{
public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance)
{
instance.Table(Inflector.Net.Inflector.Pluralize(instance.EntityType.Name));
}
}

当 Facility 从 Entity 继承时,Facility 确实会运行此方法。当它从 Location 继承时,它不会

编辑 2
以为我会发布所有内容...
Database diagram
public class AutoPersistenceModelGenerator : IAutoPersistenceModelGenerator
{

#region IAutoPersistenceModelGenerator Members

public AutoPersistenceModel Generate()
{
var mappings = new AutoPersistenceModel();
mappings.AddEntityAssembly(typeof(Person).Assembly).Where(GetAutoMappingFilter);
mappings.Conventions.Setup(GetConventions());
mappings.Setup(GetSetup());
mappings.IgnoreBase<Entity>();
mappings.IgnoreBase(typeof(EntityWithTypedId<>));
mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();

return mappings;

}

#endregion

private Action<AutoMappingExpressions> GetSetup()
{
return c =>
{
c.FindIdentity = type => type.Name == "Id";
};
}

private Action<IConventionFinder> GetConventions()
{
return c =>
{
c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ForeignKeyConvention>();
c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.HasManyConvention>();
c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.HasManyToManyConvention>();
c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ManyToManyTableNameConvention>();
c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.PrimaryKeyConvention>();
c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ReferenceConvention>();
c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.TableNameConvention>();
};
}

/// <summary>
/// Provides a filter for only including types which inherit from the IEntityWithTypedId interface.
/// </summary>

private bool GetAutoMappingFilter(Type t)
{
return t.GetInterfaces().Any(x =>
x.IsGenericType &&
x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>));
}
}

最佳答案

您是否设置了 convention ?

public class TableNameConvention : IClassConvention
{
public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance)
{
string typeName = instance.EntityType.Name;

instance.Table(Inflector.Net.Inflector.Pluralize(typeName));
}
}

关于fluent-nhibernate - Fluent nHibernate Automapping 不创建复数表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3579806/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com