具有自定义结果表的实体框架核心相关数据 [英] Entity Framework Core Related Data with custom result table

查看:46
本文介绍了具有自定义结果表的实体框架核心相关数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是 使用asp.net核心1.1的电厂预算控制系统  

我的模型如下所示:

  



     公共课BudgetAuthority

        {

            public int ID {get;组; }¥b $ b            [必填]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共字符串  AuthorityName {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual ICollection< REHPViewModelData> REHPData {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; }


  &NBSP;公共类BudgetHead

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int ID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [必填]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共字符串BudgetHeadName {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [必填]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共字符串BudgetHeadDescription {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual ICollection< REHPViewModelData> REHPData {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; }


  &NBSP;公共课BudgetEear

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int ID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [必填]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public string BudgetYearName {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共虚拟ICollection< BudgetYearlyAllocation> BudgetYearlyAllocation {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual ICollection< REHPViewModelData> REHPData {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; }


  &NBSP;公共课BudgetYearlyAllocation

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int ID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [必填]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [DisplayFormat(DataFormatString =" {0:N}")]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共十进制AllocatedAmount {get;组; }¥b $ b    

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int BudgetYearID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [ForeignKey(" BudgetYearID")]
$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual BudgetYear BudgetYear {get;组; }¥b $ b    

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   public int PowerPlantID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [ForeignKey(" PowerPlantID")]
$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共虚拟PowerPlants PowerPlants {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; }


 



  &NBSP;公共级PowerPlants

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int ID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [必填]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public string PowerPlantName {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual ICollection< REHPViewModelData> REHPData {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共虚拟ICollection< BudgetYearlyAllocation> BudgetYearlyAllocation {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual ICollection< ApplicationUser> ApplicationUser {get;组; }¥b $ b  &NBSP; }¥b $ b  &NBSP;公共课WorkCategories

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int ID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [必填]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public string WorkCategoriesName {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual ICollection< REHPViewModelData> REHPData {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; }


  &NBSP;公共类REHPViewModelData

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int ID {get;组; }&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;  

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [必填]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [DisplayFormat(DataFormatString =" {0:N}")]

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共小数ApprovedAmount {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP;   

  &NBSP; &NBSP; &NBSP; &NBSP;   

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int PowerPlantID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [ForeignKey(" PowerPlantID")]
$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共虚拟PowerPlants PowerPlants {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP;   

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int BudgetHeadID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [ForeignKey(" BudgetHeadID")]
$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共虚拟BudgetHead BudgetHead {get;组; }&NBSP; &NBSP;   

  &NBSP; &NBSP; &NBSP; &NBSP;   

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int WorkCategoriesID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [ForeignKey(" WorkCategoriesID")]
$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual WorkCategories WorkCategories {get;组; }&NBSP; &NBSP; &NBSP;   

  &NBSP; &NBSP; &NBSP; &NBSP;   

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int AuthorityID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [ForeignKey(" AuthorityID")]
$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;公共虚拟BudgetAuthority BudgetAuthority {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP;  

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public int BudgetYearID {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; [ForeignKey(" BudgetYearID")]
$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; public virtual BudgetYear BudgetYear {get;组; }¥b $ b  &NBSP; &NBSP; &NBSP; }¥b $ b    

$


$
示例  BudgetAuthority表格数据是&bbsp; b

  &NBSP; ID 权威名称

  &NBSP; 1 MD

  &NBSP; 2 GM



$


示例BudgetHead表数据是&bbsp; b
$
  &NBSP; ID BudgetHeadName
BudgetHeadDescription

  &NBSP; 1 A / budget
计划旅行

  &NBSP; 2 B /预算
乘车旅行

  &NBSP; 3 C /预算
旅行用于运送



示例  BudgetYear Table数据是&bbsp; b

  &NBSP; ID BudgetYearName

  &NBSP; 1 2017年¥b $ b  &NBSP; 2 2018年
  &NBSP; 3 2019年


示例BudgetYearlyAllocation表数据是 



  &NBSP; ID AllocatedAmount
BudgetYearID PowerPlantID

  &NBSP; 1 1000
1 1

  &NBSP; 2 900
1 2

  &NBSP; 3 800
1 3



示例  PowerPlants表数据为


  &NBSP; ID&NBSP; PowerPlantName

  &NBSP; 1 PowerStationOne

  &NBSP; 2 PowerStationTwo

  &NBSP; 3 PowerStationThree



¥b $ b示例工作类别表数据是



  &NBSP; ID WorkCategoriesName

  &NBSP; 1 电气

  &NBSP; 2 民事

  &NBSP; 3 机械

  &NBSP; 4 一般



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


   



  &NBSP;   ID(1)BudgetYearIDColumn(2)PowerPlantIDColumn 
(3)TotalElectricalAmountColumn  &NBSP; (4)Nos
(5)TotalMechnicalColumn  (6)第&NBSP; (7)TotalCivilColumn  &NBSP; (8)编号(6)TotalGeneralColumn  (9)Nos
(10)TotalAmountColumn  (11)AllocatedAmountOfBudgetYearlyAllocationTablewithPowerPlantID - (10)TotalAmount列  &NBSP;(12)&MDAuthorityNosColumn NBSP; (13)GMAuthorityNosColumn

    

  &NBSP; &NBSP; 1&NBSP; &NBSP;   1
1 100  &NBSP;   3
100 2
200 1 100
5 500
1000-500 = 500  &NBSP; 8&NBSP;   3

  &NBSP; &NBSP; 2&NBSP; &NBSP;   1
2 100  &NBSP;   3
100 2
200 1 100
5 500
900-500 = 400 8
3

  &NBSP; &NBSP; 3&NBSP; &NBSP;   1
3 100  &NBSP;   3
100 2
200 1 100
5 500
800-500 = 300  &NBSP; &NBSP; 8&NBSP; &NBSP; 3&NBSP;   
$


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



  &NBSP; ID(1)BudgetYearIDColumn(2)PowerPlantIDColumn 
(3)TotalElectricalAmountColumn  &NBSP; (4)Nos
(5)TotalMechnicalColumn  (6)第&NBSP; (7)TotalCivilColumn  &NBSP; (8)编号(6)TotalGeneralColumn  (9)Nos
(10)TotalAmountColumn  (11)AllocatedAmountOfBudgetYearlyAllocationTablewithPowerPlantID - (10)TotalAmount列  &NBSP;(12)&MDAuthorityNosColumn NBSP; (13)GMAuthorityNosColumn

  &NBSP; &NBSP;   

  &NBSP; &NBSP; 1&NBSP; &NBSP;   2017
PowerPlantOne 100.00  &NBSP;   3
100.00 2
200.00 1
100.00 5
500.00 500.00&NBSP; &NBSP; 8&NBSP;   3

  &NBSP; &NBSP; &NBSP;   

  &NBSP; &NBSP; 2&NBSP; &NBSP;   2017
PowerPlantTwo 100.00  &NBSP;   3
100.00 2
200.00 1
100.00 5
500.00 400.00&NBSP; &NBSP; 8&NBSP;   3

  &NBSP; &NBSP; 3&NBSP; &NBSP;   2017
PowerPlantThree 100.00  &NBSP;   3
100.00 2
200.00 1
100.00 5
500.00 300.00&NBSP; &NBSP; 8&NBSP;   3

  &NBSP; &NBSP; &NBSP;   



请帮我这个结果表可以在REHPViewModelData中显示

模型和  REHPViewModelData不包含BudgetAllocation表,但没有关系 和&NBSP;现在分类的REHPViewModelData 列和BudgetAuthority列,包含关系类别和预算权限表。结果表  sperate categories列和ButgetAuthority列中的
。如何进行新的模型设计和编码谢谢。



$





 




解决方案

http://social.msdn.microsoft.com/Forums/en-US/home? forum = adodotnetentityframework


这是你应该发布的地方。


My project is  Power Plant Budget Control System with asp.net core 1.1  
My Models is look like this:
  

     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; }
        }
    



Example  BudgetAuthority Table data is 

    ID AuthorityName
    1 MD
    2 GM



Example BudgetHead Table data is 

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

Example  BudgetYear Table data is 

    ID BudgetYearName
    1 2017
    2 2018
    3 2019

Example BudgetYearlyAllocation Table data is 

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

Example  PowerPlants Table Data is

    ID  PowerPlantName
    1 PowerStationOne
    2 PowerStationTwo
    3 PowerStationThree


Example WorkCategories Table data is

    ID WorkCategoriesName
    1 Electrical
    2 Civil
    3 Mechanical
    4 General

I want  Table result of  Only Budget years and  power plant  data details Table data example ind sql database data is

   

     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 result is looklike this-

    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
          

Please help me this result table can be show in REHPViewModelData
Model and  REHPViewModelData is not include BudgetAllocation table with not relationship  and  now REHPViewModelData of Categroeis  column and BudgetAuthority Column with relationship Categories and Budget Authority Tables.Result table  in sperate categories columns and ButgetAuthority Columns. How to do new model design and coding thank.





 


解决方案

http://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

it is where you should post.


这篇关于具有自定义结果表的实体框架核心相关数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆