问题描述
我想在一个级别上有一个Table类型,在另一个级别上有一个Table for hierarchy。是否可能?
描述在这里 - >
我有这些类: p>
public class BaseItem
{
public int Id {get;组; }
}
public class Item:BaseItem
{
}
public class Child1:Item
{
}
public class Child2:Item
{
}
BaseItem和Item而不是Child1和Child2
我试试这个映射:
public class BaseItemMap:ClassMap< BaseItem>
{
public BaseItemMap()
{
Id(p => p.Id).Column(BaseItemId);
}
}
public class ItemMap:SubclassMap< Item>
{
public Item()
{
KeyColumn(BaseItemId);
//注意:这行不会编译
//因为ItemMap应该是SubclassMap而
//我不能使用ClassMap!
DiscriminateSubClassesOnColumn(ItemType);
}
}
public class Child1Map:SubclassMap< Child1>
{
Public BuildingNewsMap()
{
DiscriminatorValue(@Child1);
}
}
public class Child2Map:SubclassMap< Child2>
{
Public BuildingNewsMap()
{
DiscriminatorValue(@Child2);
$ / code $ / pre
请帮助我!
解决方案有点尴尬,但确实有效。我包括一些属性来显示它们的映射
pre $ c $ public class BaseItem
{
public virtual int Id {get;保护组}
public virtual DateTime Created {get;组; }
}
public class Item:BaseItem
{
public virtual string Name {get;组; }
}
public class Child1:Item
{
public virtual int Property1 {get;组; }
}
public class Child2:Item
{
public virtual int Property2 {get;组; }
}
public class ItemMap:ClassMap< Item>
public ItemMap()
{
Id(p => p.Id).Column(BaseItemId)。GeneratedBy.HiLo(100);
Join(BaseItemTable,join =>
{
join.KeyColumn(BaseItemId);
join.Map(x => x。创建);
});
DiscriminateSubClassesOnColumn(ItemType);
}
}
public class Child1Map:SubclassMap< Child1>
{
public Child1Map()
{
DiscriminatorValue(Child1);
Map(x => x.Property1);
}
}
public class Child2Map:SubclassMap< Child2>
{
public Child2Map()
{
DiscriminatorValue(Child2);
Map(x => x.Property2);
}
}
I want to have Table per Type in one level and one Table for hierarchy in another level.Is it possible?
description is here ->
I have these classes:
public class BaseItem
{
public int Id{ get; set; }
}
public class Item : BaseItem
{
}
public class Child1 : Item
{
}
public class Child2 : Item
{
}
I wanna have tables for "BaseItem" and "Item" and not for "Child1" and "Child2"
I try this mappings:
public class BaseItemMap : ClassMap<BaseItem>
{
public BaseItemMap()
{
Id(p => p.Id).Column("BaseItemId");
}
}
public class ItemMap : SubclassMap<Item>
{
public Item()
{
KeyColumn("BaseItemId");
//note: this line does not compiled
// because "ItemMap" should be of "SubclassMap" and
// I can not use "ClassMap"!
DiscriminateSubClassesOnColumn("ItemType");
}
}
public class Child1Map : SubclassMap<Child1>
{
public BuildingNewsMap()
{
DiscriminatorValue(@"Child1");
}
}
public class Child2Map : SubclassMap<Child2>
{
public BuildingNewsMap()
{
DiscriminatorValue(@"Child2");
}
}
help me please!
a bit awkward but does work. I included some properties to show the mapping of them
public class BaseItem
{
public virtual int Id { get; protected set; }
public virtual DateTime Created { get; set; }
}
public class Item : BaseItem
{
public virtual string Name { get; set; }
}
public class Child1 : Item
{
public virtual int Property1 { get; set; }
}
public class Child2 : Item
{
public virtual int Property2 { get; set; }
}
public class ItemMap : ClassMap<Item>
{
public ItemMap()
{
Id(p => p.Id).Column("BaseItemId").GeneratedBy.HiLo("100");
Join("BaseItemTable", join =>
{
join.KeyColumn("BaseItemId");
join.Map(x => x.Created);
});
DiscriminateSubClassesOnColumn("ItemType");
}
}
public class Child1Map : SubclassMap<Child1>
{
public Child1Map()
{
DiscriminatorValue("Child1");
Map(x => x.Property1);
}
}
public class Child2Map : SubclassMap<Child2>
{
public Child2Map()
{
DiscriminatorValue("Child2");
Map(x => x.Property2);
}
}
这篇关于流利的NHibernate两级继承问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!