LINQ的更新行,如果新行插入另一个表
问题描述:
我有4代表在这里,我试图更新时,新的行与另一个表中使用LINQLINQ的更新行,如果新行插入另一个表
CustomerTable的添加最后一项排:
:CustomerId Name EmailId
-------------------------
1 Paul [email protected]
2 John [email protected]
下表我对每个LoyatyType
LoyaltyPointTable分配点
LoyaltyPointsId LoyaltyType Points
---------------------------------------
1 Registration 10
2 Loginstatus 1
3 Downloading 10
4 Redemming 1
5 Sharing 20
6 Refer 10
LoyaltyDetailsTable:
LoyaltyDetailsId LoyaltyPointsId CustomerId Dates
-------------------------------------------------
1 1 1 2015-01-22
2 2 1 2015-01-22
3 3 2 2015-01-22
4 3 1 2015-01-22
5 4 1 2015-01-22
6 4 1 2015-01-24
7 2 1 2015-01-24 // here one new row is added based on LoginStatus
他做登录一次,所以他的LoginStatus点是1,现在我想在下面更新另一个表中这一点
预期输出:
PriceClaimTable
PriceClaimId CustomerId PriceId Current Points
1 2 22 150
2 1 23 200 // here update the last row of CustomerId as 231
//based on every new entry on LoyaltyDetailsTable
说,如果他再次登录200 + 1 = 201
然后他被下载201 + 10 = 211
然后,他不共享211 + 20 = 231
我可以使用sql在LINQ和触发找到解决方案?
答
如何创建加入LoyaltyPointTable的LoyaltyDetailsTable的视图,以在每个客户之间累积LoyaltyPointTable.Points,例如,东西(取决于您的SQL方言)
CREATE VIEW PriceClaimView
AS
SELECT CustomerId, SUM(LPT.Points) AS CurrentPoints
FROM LoyaltyDetailsTable LDT INNER JOIN LoyaltyPointTable LPT ON LDT.LoyaltyPointsId = LPT.LoyaltyPointsId
GROUP BY CustomerId
您正在使用哪些DBMS? Postgres的?甲骨文? – 2015-02-10 13:33:05
我正在使用Sqlserver 2012 – stom 2015-02-10 13:36:53