FluentNhibernate映射

时间:2011-09-07 01:33:48

标签: fluent-nhibernate fluent-nhibernate-mapping

这是我的实体关系图

http://s3.subirimagenes.com:81/privadas/1605595base.png

场景:这些是我简化的课程

public class plaserv
{
public plaserv()
{
    plamoviles = new List<plamoviles>();
    asistencia = new List<asistencia>();
    plaattach = new List<plaattach>();
}
public virtual double id_planilla { get; private set; }
public virtual double id_parte { get; set; }
...
public virtual int id_tservicio { get; set; }
public virtual int id_legacar { get; set; }
...
public virtual personal personal { get; set; }
public virtual IList<plamoviles> plamoviles { get; private set; }
public virtual plaparte plaparte { get; set; }
public virtual IList<asistencia> asistencia { get; private set; }
public virtual IList<plaattach> plaattach { get; private set; }
}

public class plaparte
{
    public virtual double id_planilla { get; private set; }
    ...
}

public class plamoviles
{
    public plamoviles()
    {
        plamoviles_combustible = new List<combustible>();
        plamoviles_moviles = new List<movil>();
    }

    public virtual double id { get; private set; }
    public virtual double id_planilla { get; set; }
    public virtual int nmovil { get; set; }
    public virtual decimal cant_combustible { get; set; }
    public virtual int id_tcombustible { get; set; }

    public virtual IList<combustible> plamoviles_combustible { get; private set; }
    public virtual IList<movil> plamoviles_moviles { get; private set; }
}

public class plaattach
{
    public virtual double id { get; set; }
    public virtual double id_planilla { get; set; }
    public virtual byte[] archivo { get; set; }
}

public class personal
{
    public personal()
    {
        personal_jerarquia = new List<jerarquia>().OrderBy(x => x.posicion).ToList();
    }

    public virtual double id_legajo { get; set; }
    public virtual string nomyape { get; set; }
    public virtual int id_jerar { get; set; }
    ..

    public virtual IList<jerarquia> personal_jerarquia { get; private set; }
}
   .....

这些是我的映射

    public class plaservMap : ClassMap<plaserv>
{
    public plaservMap()
    {
        Table("plaserv");

        Id(x => x.id_planilla);
        Map(x => x.autor_llamada).Length(50).Not.Nullable();
        Map(x => x.tipo_llamada).Length(3).Not.Nullable();
        Map(x => x.direccion).Length(100).Not.Nullable();
        Map(x => x.hora_aviso).Length(5).Not.Nullable();
        Map(x => x.hora_salida).Length(5).Not.Nullable();
        Map(x => x.hora_regreso).Length(5);
        Map(x => x.fecha);
        Map(x => x.fecha_regreso);
        Map(x => x.cant_moviles);
        Map(x => x.cant_perso);
        Map(x => x.id_legacar);

        References(x => x.personal); //muchos a uno
        HasMany(x => x.plamoviles).Inverse().Cascade.All();
        HasMany(x => x.plaattach).Inverse().Cascade.All();
    }
}

使用正确

References(x => x.personal)

我应该在课堂上添加个人关闭个人与plaserv之间的关系? 我应该添加类似个人的东西

HasMany(x => x.plaserv).Inverse().Cascade.All();

1 个答案:

答案 0 :(得分:0)

我决定通过Automap实现