具有自定义结果表的实体框架核心相关数据

时间:2017-12-11 06:00:07

标签: sql-server asp.net-core entity-framework-core

我的项目是电厂预算控制系统,带有asp.net核心1.1
我的模型看起来像这样:

 public class BudgetAuthority
    {
        public int ID { get; set; }
        [Required]
        public string  AuthorityName { get; set; }
        public virtual ICollection<REHPViewModelData> REHPData { get; set; }
    }

public class BudgetHead
    {
        public int ID { get; set; }
        [Required]
        public string BudgetHeadName { get; set; }
        [Required]
        public string BudgetHeadDescription { get; set; }
        public virtual ICollection<REHPViewModelData> REHPData { get; set; }
    }

public class BudgetYear
    {
        public int ID { get; set; }
        [Required]
        public string BudgetYearName { get; set; }
        public virtual ICollection<BudgetYearlyAllocation> BudgetYearlyAllocation { get; set; }
        public virtual ICollection<REHPViewModelData> REHPData { get; set; }
    }

public class BudgetYearlyAllocation
    {
        public int ID { get; set; }
        [Required]
        [DisplayFormat(DataFormatString = "{0:N}")]
        public decimal AllocatedAmount { get; set; }

        public int BudgetYearID { get; set; }
        [ForeignKey("BudgetYearID")]
        public virtual BudgetYear BudgetYear { get; set; }

         public int PowerPlantID { get; set; }
        [ForeignKey("PowerPlantID")]
        public virtual PowerPlants PowerPlants { get; set; }
    }



public class PowerPlants
    {
        public int ID { get; set; }
        [Required]
        public string PowerPlantName { get; set; }
        public virtual ICollection<REHPViewModelData> REHPData { get; set; }
        public virtual ICollection<BudgetYearlyAllocation> BudgetYearlyAllocation { get; set; }
        public virtual ICollection<ApplicationUser> ApplicationUser { get; set; }
}
public class WorkCategories
    {
        public int ID { get; set; }
        [Required]
        public string WorkCategoriesName { get; set; }
        public virtual ICollection<REHPViewModelData> REHPData { get; set; }
    }

public class REHPViewModelData
    {
        public int ID { get; set; }                         
        [Required]
        [DisplayFormat(DataFormatString = "{0:N}")]
        public decimal ApprovedAmount { get; set; }


        public int PowerPlantID { get; set; }
        [ForeignKey("PowerPlantID")]
        public virtual PowerPlants PowerPlants { get; set; }

        public int BudgetHeadID { get; set; }
        [ForeignKey("BudgetHeadID")]
        public virtual BudgetHead BudgetHead { get; set; }      

        public int WorkCategoriesID { get; set; }
        [ForeignKey("WorkCategoriesID")]
        public virtual WorkCategories WorkCategories { get; set; }        

        public int AuthorityID { get; set; }
        [ForeignKey("AuthorityID")]
        public virtual BudgetAuthority BudgetAuthority { get; set; }

        public int BudgetYearID { get; set; }
        [ForeignKey("BudgetYearID")]
        public virtual BudgetYear BudgetYear { get; set; }
    }

示例BudgetAuthority表数据

ID  AuthorityName
1   MD
2   GM

示例BudgetHead表数据

ID  BudgetHeadName  BudgetHeadDescription
1   A/budget            Travelling for Plan
2   B/budget            Travelling for Car
3   C/budget            Travelling for Shipping

示例BudgetYear表数据是

ID  BudgetYearName
1   2017
2   2018
3   2019

示例BudgetYearlyAllocation表数据是

ID  AllocatedAmount     BudgetYearID    PowerPlantID
1   1000                1       1
2   900             1       2
3   800             1       3

示例PowerPlants表数据

ID      PowerPlantName
1   PowerStationOne
2   PowerStationTwo
3   PowerStationThree

示例WorkCategories表数据

ID  WorkCategoriesName
1   Electrical
2   Civil
3   Mechanical
4   General

我想要只有预算年的表结果和电厂数据详细信息表数据示例ind sql数据库数据是

 ID (1)BudgetYearIDColumn (2)PowerPlantIDColumn     (3)TotalElectricalAmountColumn    (4)Nos    (5)TotalMechnicalColumn  (6)Nos  (7) TotalCivilColumn    (8)Nos (6)TotalGeneralColumn  (9)Nos   (10)TotalAmountColumn  (11) AllocatedAmountOfBudgetYearlyAllocationTablewithPowerPlantID – (10)TotalAmount Column   (12)MDAuthorityNosColumn  (13)GMAuthorityNosColumn

  1     1   1   100     3   100  2  200  1  100  5  500  1000-500=500    8   3
  2     1   2   100     3   100  2  200  1  100  5  500  900-500=400     8   3
  3     1   3   100     3   100  2  200  1  100  5  500  800-500=300     8   3    

Index.chtml结果看起来像这样 -

ID (1)BudgetYearIDColumn (2)PowerPlantIDColumn      (3)TotalElectricalAmountColumn    (4)Nos    (5)TotalMechnicalColumn  (6)Nos  (7) TotalCivilColumn    (8)Nos (6)TotalGeneralColumn  (9)Nos   (10)TotalAmountColumn  (11) AllocatedAmountOfBudgetYearlyAllocationTablewithPowerPlantID – (10)TotalAmount Column   (12)MDAuthorityNosColumn  (13)GMAuthorityNosColumn

 1     2017 PowerPlantOne   100.00     3    100.00   2  200.00   1  100.00   5  500.00   500.00    8   3

 2     2017 PowerPlantTwo   100.00     3    100.00   2  200.00   1  100.00   5  500.00   400.00    8   3
 3     2017 PowerPlantThree 100.00     3    100.00   2  200.00   1  100.00   5  500.00   300.00    8   3

请帮我这个结果表可以在REHPViewModelData中显示 Model和REHPViewModelData不包括BudgetAllocation表没有关系,现在包含Categroeis列的REHPViewModelData和BudgetAuthority列,其中包含sperate类别列和ButgetAuthority列中的关系Categories和Budget Authority Tables.Result表。如何进行新的模型设计和编码谢谢。

0 个答案:

没有答案