我正在使用Factura和DetalleFactura表,问题是我得到一个Factura没有填写DetalleFactura的集合。
clsFacturaModel和clsDetalleFacturaModel具有复合ID。
我包含有关其他类的其他信息,因为它们是复合ID的一部分。
型号:
public class clsCiaModel
{
public virtual string Cve_cia { get; set; }
public virtual string Nom_cia { get; set; }
public virtual clsDireccion Direccion { get; set; }
public virtual string Rfc_cia { get; set; }
}
public class clsPlantaModel
{
public virtual clsCiaModel Cia_pla { get; set; }
public virtual string Cve_pla { get; set; }
public virtual string Nom_pla { get; set; }
public virtual clsDireccion Direccion { get; set; }
public virtual string Tel1_pla { get; set; }
public virtual long Fnvta_pla { get; set; }
}
public abstract class clsaBase
{
public virtual clsPlantaModel Planta { get; set; }
}
public class clsFacturaModel : clsaBase
{
public virtual string Tfac_fac { get; set; }
public virtual int Fol_fac { get; set; }
public virtual string Ser_fac { get; set; }
public virtual DateTime? Fec_fac { get; set; }
public virtual clsClienteModel Numcte_fac { get; set; }
public virtual string Tpa_fac { get; set; }
public virtual string Edo_fac { get; set; }
public virtual string Impr_fac { get; set; }
public virtual clsCfdModel Cfd { get; set; }
public virtual IList<clsDetalleFacturaModel> Detalle { get; set; }
}
public class clsDetalleFacturaModel : clsaBase
{
public virtual clsFacturaModel Fol_dfac { get; set; }
public virtual short Mov_dfac { get; set; }
public virtual string Tid_dfac { get; set; }
public virtual int? Fnvta_dfac { get; set; }
public virtual int? Ffis_dfac { get; set; }
public virtual decimal? Tlts_dfac { get; set; }
public virtual string Tpr_dfac { get; set; }
public virtual decimal? Pru_dfac { get; set; }
public virtual decimal? Ivap_dfac { get; set; }
public virtual decimal? Simp_dfac { get; set; }
}
地图:
public clsCiaMap()
{
Table("cia");
Id(c => c.Cve_cia, "cve_cia");
Map(c => c.Nom_cia, "nom_cia").Length(40);
Map(c => c.Rfc_cia, "rfc_cia").Length(15).Nullable();
Component(c => c.Direccion,
d =>
{
d.Map(dir => dir.Dir, "dir_cia").Length(40).Nullable();
d.Map(dir => dir.Col, "col_cia").Length(40).Nullable();
d.Map(dir => dir.Ciu, "ciu_cia").Length(40).Nullable();
});
}
public class clsPlantaMap : ClassMap<clsPlantaModel>
{
public clsPlantaMap()
{
Table("planta");
CompositeId()
.KeyProperty(p => p.Cve_pla, "cve_pla")
.KeyReference(p => p.Cia_pla, "cia_pla");
Map(p => p.Nom_pla, "nom_pla").Length(40).Nullable();
Map(p => p.Tel1_pla, "tel1_pla").Length(30).Nullable();
Map(p => p.Fnvta_pla, "fnvta_pla");
Component(c => c.Direccion,
d =>
{
d.Map(dir => dir.Dir, "dir_pla").Length(40).Nullable();
d.Map(dir => dir.Col, "col_pla").Length(40).Nullable();
d.Map(dir => dir.Ciu, "ciu_pla").Length(30).Nullable();
});
}
}
public class clsFacturaMap : ClassMap<clsFacturaModel>
{
public clsFacturaMap()
{
Table("factura");
CompositeId()
.KeyProperty(f => f.Fol_fac, "fol_fac")
.KeyProperty(f => f.Ser_fac, "ser_fac")
.KeyReference(f => f.Planta, "pla_fac", "cia_fac");
Map(f => f.Edo_fac, "edo_fac").Length(1).Nullable();
Map(f => f.Fec_fac, "fec_fac").Nullable();
Map(f => f.Impr_fac, "impr_fac").Nullable();
References<clsClienteModel>(f => f.Numcte_fac, "numcte_fac").Nullable().Not.LazyLoad();
Map(f => f.Tfac_fac, "tfac_fac").Length(1);
HasMany<clsDetalleFacturaModel>(f => f.Detalle)
.KeyColumns.Add("fol_dfac", "ser_dfac", "pla_dfac", "cia_dfac")
.Cascade.AllDeleteOrphan()
.Inverse()
.AsBag()
.Not.LazyLoad();//COLLECTION EMPTY
}
}
public class clsDetalleFacturaMap : ClassMap<clsDetalleFacturaModel>
{
public clsDetalleFacturaMap()
{
Table("det_fac");
CompositeId()
.KeyProperty(df => df.Mov_dfac, "mov_dfac")
.KeyReference(df => df.Fol_dfac, "fol_dfac", "ser_dfac", "pla_dfac", "cia_dfac");
Map(df => df.Ffis_dfac, "ffis_dfac").Nullable();
Map(df => df.Fnvta_dfac, "fnvta_dfac").Nullable();
Map(df => df.Ivap_dfac, "ivap_dfac").Nullable();
Map(df => df.Pru_dfac, "pru_dfac").Nullable();
Map(df => df.Simp_dfac, "simp_dfac").Nullable();
Map(df => df.Tid_dfac, "tid_dfac").Length(1).Nullable();
Map(df => df.Tlts_dfac, "tlts_dfac").Nullable();
Map(df => df.Tpr_dfac, "tpr_dfac").Length(3).Nullable();
}
}
我没有收到任何错误,但收集(Detalle)总是空的