简体   繁体   English

C#EF6更新非相关表的值

[英]C# EF6 Update Values to non related tables

I have a question about updating a non related table. 我有一个关于更新非相关表的问题。

I have a TableA which has: 我有一个TableA,它有:

Id     Code      Value(Int)
1      2201      3
2      2202      5

And a TableB which has: 和一个TableB有:

Id     Code      Value(Int)
1      2201      2
2      2202      1 

I need to Update a table (TableC) which is non related with both TableA and TableB with Sum of Values from TableA and TableB. 我需要更新一个与TableA和TableB无关的表(TableC),其中TableA和TableB的值为Sum。

TableB: 表B:

Code       SumValues
2201       5
2202       6

Everytime I add values to TableA and TableB, I need to Update TableC with: Sum (Existing Values in TableC + Current Value added to TableA + Current Value added to TableB) 每次我向TableA和TableB添加值时,我需要更新TableC:Sum(TableC中的现有值+添加到TableA的当前值+添加到TableB的当前值)

Is this possible? 这可能吗? What kind of relation between tables do I need? 我需要什么样的表格关系? How to achieve this? 怎么做到这一点?

Thanks. 谢谢。

Your tableC should be like this : 你的tableC应该是这样的:

Id     Code     SumValues

1       2201       5
2       2202       6

You have to manually insert the values into TableC when you update the TableA and TableB.The only relationship on it is FK relationship with the Code field.Hope you have another table for maintaining Codes .Like a Master table for Codes . 你必须将这些值手动插入到表C,当你更新表A和TableB.The只关系它是FK与关系Code field.Hope你必须保持另一个表Codes 。就像一个主表Codes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM