Nhibernate字段在继承的类之间进行映射

时间:2012-03-05 15:33:55

标签: c# nhibernate nhibernate-mapping

我有两个具有相同字段的类及其相应的表也是相同的。我的意思是那些表具有相同的列具有相同的名称。我在数据库设计中将其分开,因为我不确定它是否会影响数据的持久性。

我的问题是:

我可以使用公共字段实现一个根类,并将其归入列的名称,然后在子类中定义哪个是对应的表?

例如,班级RootCard

public virtual class IRootCard: ModelEntity, IEntity
    {

        private User _player;
        [ManyToOne(Column = "player_id")]
        public virtual User Player
        {
            get { return _player; }
            set { _player = value; }
        }

    private Lobby _game;
    [ManyToOne(Column = "game_id",NotNull = true)]
    public virtual Lobby Game
    {
        get { return _game; }
        set { _game = value; }
    }

.... }

然后,只使用相应表的定义实现两个子类CardHistoricCard

[Class(Table = "bingogame_cardtoplay")]
public class Card: IRootCard
{
}

[Class(Table = "bingogame_cardtoplay")]
public class HistoricCard: IRootCard
{
}

它是否在每个表中正确映射而不影响另一个?

0 个答案:

没有答案