简体   繁体   中英

C# EF6 Update Values to non related tables

I have a question about updating a non related table.

I have a TableA which has:

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

And a TableB which has:

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.

TableB:

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)

Is this possible? What kind of relation between tables do I need? How to achieve this?

Thanks.

Your tableC should be like this :

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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