1
Giveable의 하위 클래스를 허용하기 위해 Giveaway.Giveable을 사용하려하지만 Giveable은 추상 기본 클래스이므로 실제로 매핑되지 않았습니다. TPT 대신 계층 당 테이블 사용하고 있습니다.Fluent NHibernate 자동 매핑을 사용하는 TPH의 일대 다에서 내 추상 기본 클래스를 어떻게 사용할 수 있습니까?
나는 다른 사람들을 돕기위한 수업을 포함하고 있으며, NHibernate에 대한보다 실제적인 예를 제공하고있다. 모든 코드를 실례 해 주길 바란다.
예외 : 공짜가 매핑되지 않은 클래스를 참조하는 테이블의 연관 : Giveable
AutoMap.AssemblyOf<Giveaway>(cfg).UseOverridesFromAssemblyOf<UserMappingOverride>()
.Conventions.Add(
PrimaryKey.Name.Is(x => "ID"),
DefaultLazy.Always(),
DefaultCascade.Delete(),
DynamicInsert.AlwaysTrue(),
DynamicUpdate.AlwaysTrue(),
OptimisticLock.Is(x => x.Dirty()),
ForeignKey.EndsWith("ID")))).ExposeConfiguration(BuildSchema)
public abstract class Giveable
{
ISet<Giveaway> giveaways;
public Giveable() : base()
{
giveaways = new HashedSet<Giveaway>();
}
public virtual ISet<Giveaway> Giveaways
{
get { return giveaways; }
set { giveaways = value; }
}
public virtual int ID { get; set; }
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
var toCompareWith = obj as Giveable;
return toCompareWith != null && ((ID == toCompareWith.ID));
}
public override int GetHashCode()
{
int toReturn = base.GetHashCode();
toReturn ^= ID.GetHashCode();
return toReturn;
}
}
public class Giveaway
{
ISet<Entry> entries;
public Giveaway() : base()
{
entries = new HashedSet<Entry>();
CreatedDate = DateTime.UtcNow;
}
public virtual DateTime CreatedDate { get; private set; }
public virtual DateTime? EndDate { get; set; }
public virtual ISet<Entry> Entries
{
get { return entries; }
set { entries = value; }
}
public virtual Giveable Giveable { get; set; }
public virtual int ID {get;set;}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
var toCompareWith = obj as Giveaway;
return toCompareWith != null && ((ID == toCompareWith.ID));
}
public override int GetHashCode()
{
int toReturn = base.GetHashCode();
toReturn ^= ID.GetHashCode();
return toReturn;
}
}
public class GiveableMappingOverride : IAutoMappingOverride<Giveable>
{
public void Override(AutoMapping<Giveable> mapping)
{
mapping.DiscriminateSubClassesOnColumn("GiveableType");
mapping.Map(x => x.Name).Length(200).Not.Nullable();
mapping.Map(x => x.ImageName).Length(200).Nullable();
mapping.Map(x => x.ReleaseDate).Not.Nullable();
mapping.HasMany(x => x.Giveaways)
.Fetch.Select()
.AsSet()
.Inverse()
.LazyLoad();
}
}
public class GiveawayMappingOverride : IAutoMappingOverride<Giveaway>
{
public void Override(AutoMapping<Giveaway> mapping)
{
mapping.Map(x => x.ThingID).Length(20).Nullable();
mapping.Map(x => x.Text).Length(2000).Not.Nullable();
mapping.Map(x => x.CreatedDate).Not.Nullable();
mapping.Map(x => x.Platform).Not.Nullable();
mapping.Map(x => x.Type).Not.Nullable();
mapping.HasMany(x => x.Entries);
mapping.References(x => x.Giveable).Not.Nullable();
mapping.References(x => x.User).Not.Nullable();
mapping.References(x => x.Winner);
}
}