-2

在 NHibernate 中映射对象集合的最佳方法是什么?现在我正在使用袋子,但也许另一种方法可以更有效?

4

1 回答 1

0

之前戴过 Bag 和 ClassMapping 的东西,跟这个很像:

        Bag(am => am.AlumnoMateriaId, map =>
            {
                map.Table("Calificacion");
                map.Cascade(Cascade.None);
                map.Key(k =>
                    {
                        k.Column("AlumnoId");
                        k.ForeignKey("FK_Calificacion_AlumnoMateria");
                    });
            }, rel => rel.ManyToMany(p => p.Column("AlumnoId")));

现在使用 NHibernate.Mapping.Attributes,一个类看起来像:

使用 NHMA = NHibernate.Mapping.Attributes;

[NHMA.Class(Table = " Calificacion ")]

公共类 Calificacion { [NHMA.Id(0, Name = "id", TypeType = typeof(Int32), Column = "Id", Access = "field")] [NHMA.Generator(1, Class = "native") ] 公共 Int32 标识;

    public virtual Int32 Id
    {
        get { return id; }
        set { id = value; }
    }

    [NHMA.ManyToOne(2, Name = "calificacion", Access = "field", Column = "CalificacionID",
    Class = "Calificacion", ClassType = typeof(Calificacion),
    ForeignKey = "FK_Calificacion_Alumno", NotNull = false)]
    private Calificacion calificaion;

    public virtual Calificacion Calificaion
    {
        get { return calificaion; }
        set { calificaion = value; }
    }



    [NHMA.Property(Name = "nombre", Access = "field", Column = "Nombre", Length = 50)]
    private string nombre;

    public virtual string Nombre
    {
        get { return nombre; }
        set { nombre = value; }
    }

}

于 2013-07-15T18:58:13.580 回答