我正在尝试使用Entity Framework获取某些数据;我的模型具有projectconfig,它与units表具有一对多的关系,unitpaypoints的一对多关系,paypoint的一对多,tradephase表的关系是多对一。
我有一个ICollection
的单位,从projectconfig,一个ICollection
的单位支付点到单位支付点,支付点是unitpaypoint贸易阶段的对象,是支付点类中的对象。
我基本上是在Entity Framework中尝试执行此select语句。
var enumerable = DataServiceLocator.GetKPMProjectConfig_DAO().GetProjectConfigsByProjectID(project_id, Context).Select(x => new PMRUnitTypeModel
{
Project_ID = x.ProjectID,
Trade = x.KPMUnits.Any(a => a.ProjectConfigID == x.ProjectConfigI)
})
这似乎不正确,我只是不确定如何使用ICollection
来获取所有相关数据,谢谢您的建议
select distinct
pc.ProjectID, tp.Service_Type, up.SubpayAmount, up.Amount
from
[KPM].ProjectConfig pc
join
KPM.Units u on pc.ProjectConfigID = u.ProjectConfigID
join
KPM.UnitPaypoints up on up.UnitID = u.UnitID
join
KPM.Paypoint p on p.PaypointID = up.PaypointID
join
TradePhase tp on p.TP_ID = tp.TP_ID
where
pc.projectid = 121
这些是我的课程对象
namespace KmsApi.KPMMOdels
{
[Table("ProjectConfig", Schema = "KPM")]
public partial class ProjectConfig
{
public ProjectConfig()
{
Units = new HashSet<Unit>();
}
[Column("ProjectConfigID")]
public int ProjectConfigId { get; set; }
[Column("FloorID")]
public int? FloorId { get; set; }
[Column("WingID")]
public int? WingId { get; set; }
[Column("BuildingID")]
public int? BuildingId { get; set; }
[Column("ComplexID")]
public int? ComplexId { get; set; }
[Column("ProjectID")]
public int ProjectId { get; set; }
public int? FloorOrder { get; set; }
[ForeignKey("BuildingId")]
[InverseProperty("ProjectConfigs")]
public Building Building { get; set; }
[ForeignKey("ComplexId")]
[InverseProperty("ProjectConfigs")]
public Complex Complex { get; set; }
[ForeignKey("FloorId")]
[InverseProperty("ProjectConfigs")]
public Floor Floor { get; set; }
[ForeignKey("ProjectId")]
[InverseProperty("ProjectConfigs")]
public Project Project { get; set; }
[ForeignKey("WingId")]
[InverseProperty("ProjectConfigs")]
public Wing Wing { get; set; }
[InverseProperty("ProjectConfig")]
public ICollection<Unit> Units { get; set; }
}
}
namespace KmsApi.KPMMOdels
{
[Table("Units", Schema = "KPM")]
public partial class Unit
{
public Unit()
{
CustomItem1 = new HashSet<CustomItem1>();
UnitKnownA = new HashSet<UnitKnownA>();
UnitPaypoints = new HashSet<UnitPaypoint>();
}
[Column("UnitID")]
public int UnitId { get; set; }
[Column("ProjectConfigID")]
public int ProjectConfigId { get; set; }
[Column("Unit")]
public short Unit1 { get; set; }
[StringLength(10)]
public string UnitCode { get; set; }
[Column("UnitTypeID")]
public int UnitTypeId { get; set; }
[ForeignKey("ProjectConfigId")]
[InverseProperty("Units")]
public ProjectConfig ProjectConfig { get; set; }
[ForeignKey("UnitTypeId")]
[InverseProperty("Units")]
public UnitType UnitType { get; set; }
[InverseProperty("Unit")]
public ICollection<CustomItem1> CustomItem1 { get; set; }
[InverseProperty("Unit")]
public ICollection<UnitKnownA> UnitKnownA { get; set; }
[InverseProperty("Unit")]
public ICollection<UnitPaypoint> UnitPaypoints { get; set; }
}
}
namespace KmsApi.KPMMOdels
{
[Table("UnitPaypoints", Schema = "KPM")]
public partial class UnitPaypoint
{
public UnitPaypoint()
{
UnitPaypointDetails = new HashSet<UnitPaypointDetail>();
UnitPaypointOverrideVendors = new HashSet<UnitPaypointOverrideVendor>();
}
[Column("UnitPaypointID")]
public int UnitPaypointId { get; set; }
[Column("UnitID")]
public int UnitId { get; set; }
[Column("PaypointID")]
public int PaypointId { get; set; }
[Column(TypeName = "decimal(10, 2)")]
public decimal Amount { get; set; }
public bool Billable { get; set; }
[Column(TypeName = "decimal(10, 2)")]
public decimal? SubpayAmount { get; set; }
[ForeignKey("PaypointId")]
[InverseProperty("UnitPaypoints")]
public Paypoint Paypoint { get; set; }
[ForeignKey("UnitId")]
[InverseProperty("UnitPaypoints")]
public Unit Unit { get; set; }
[InverseProperty("UnitPaypoint")]
public ICollection<UnitPaypointDetail> UnitPaypointDetails { get; set; }
[InverseProperty("UnitPaypoint")]
public ICollection<UnitPaypointOverrideVendor> UnitPaypointOverrideVendors { get; set; }
}
}
namespace KmsApi.KPMMOdels
{
[Table("Paypoint", Schema = "KPM")]
public partial class Paypoint
{
public Paypoint()
{
UnitPaypoints = new HashSet<UnitPaypoint>();
}
[Column("PaypointID")]
public int PaypointId { get; set; }
[Required]
[StringLength(50)]
public string Code { get; set; }
[Required]
[StringLength(255)]
public string Description { get; set; }
[Column("TP_ID")]
public int TpId { get; set; }
[InverseProperty("Paypoint")]
public ICollection<UnitPaypoint> UnitPaypoints { get; set; }
}
}