Sharp Architecture를 사용하여 작은 응용 프로그램을 만들고 있는데 알아낼 수없는 버그가 있습니다. NHibernte 매핑과 관련이 있다고 생각합니다. 내 HttpPost Create() 메소드에서 SaveOrUpdate 호출이 테이블의 기본 키 필드에 null을 삽입하려고합니다. 내 모델에서 기본 키에 대한 선언은 public virtual int Id { get; protected set; }
입니다.SaveOrUpdate가 기본 키 필드에 NULL을 삽입하려고합니다.
newSprint.Id를 확인했으며 0입니다. 나는 문제가 내 NHibernate Mapping과 함께 있다고 생각한다. 그래서 나는 아래에 그것들 모두를 포함시켰다.
public class AutomappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(System.Type type)
{
return type.GetInterfaces().Any(x =>
x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>));
}
public override bool ShouldMap(Member member)
{
return base.ShouldMap(member) && member.CanWrite;
}
public override bool AbstractClassIsLayerSupertype(System.Type type)
{
return type == typeof(EntityWithTypedId<>) || type == typeof(Entity);
}
public override bool IsId(Member member)
{
return member.Name == "Id";
}
}
오토 지속성 모델 발생기 : 어떤 도움 누군가가 제공 할 수있는 사전에
public class AutoPersistenceModelGenerator : IAutoPersistenceModelGenerator
{
public AutoPersistenceModel Generate()
{
var mappings = AutoMap.AssemblyOf<Sprint>(new AutomappingConfiguration());
mappings.IgnoreBase<Entity>();
mappings.IgnoreBase(typeof(EntityWithTypedId<>));
mappings.Conventions.Setup(GetConventions());
mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();
return mappings;
}
private static Action<IConventionFinder> GetConventions()
{
return c =>
{
c.Add<PrimaryKeyConvention>();
c.Add<CustomForeignKeyConvention>();
c.Add<HasManyConvention>();
c.Add<TableNameConvention>();
};
}
감사
다음은 자동 매핑 구성입니다.
편집 문제는 표 이름 규칙과 관련이 있음을 알았습니다. AutoMapping 구성에서 제거하면 문제가 해결됩니다. 불필요한 코드를 제거하고 TableNameConvention 매핑을 추가하여 누군가가 그 문제를 일으킨 구체적인 이유를 설명 할 수 있기를 바랍니다.
public class TableNameConvention : IClassConvention
{
public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance)
{
instance.Table(Inflector.Net.Inflector.Pluralize(instance.EntityType.Name));
}
}
id 열에 대해 생성 된 sql을 확인 했습니까? id 기본 이름은 어디에 적용합니까? – cpoDesign