如果在另一行中插入新行,Linq 更新一行 table
Linq Update a row if new rows are inserted in another table
我这里有 4 个 table,我正在尝试使用 linq
在另一个 table 中添加新行时更新最后一个条目行
客户表:
CustomerId Name EmailId
-------------------------
1 Paul r@r.com
2 John J@j.com
下面table我为每个LoyatyType分配积分
忠诚度积分表:
LoyaltyPointsId LoyaltyType Points
---------------------------------------
1 Registration 10
2 Loginstatus 1
3 Downloading 10
4 Redemming 1
5 Sharing 20
6 Refer 10
忠诚度详情表:
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
他已经完成了一次登录,所以他的登录状态点现在是 1 我想在下面的另一个table中更新这个点
预期输出:
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
我可以在 Linq 中使用 sql 触发器并找到解决方案吗?
用户可以使用 triggers
来完成这项工作。你可以看看this写一个
如何在加入 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
1,在您的数据引擎上
你可以使用触发器
2、你的程序
你可以编写一个机制。
通常trihger会伤害性能,我会使用计划B
我这里有 4 个 table,我正在尝试使用 linq
在另一个 table 中添加新行时更新最后一个条目行客户表:
CustomerId Name EmailId
-------------------------
1 Paul r@r.com
2 John J@j.com
下面table我为每个LoyatyType分配积分
忠诚度积分表:
LoyaltyPointsId LoyaltyType Points
---------------------------------------
1 Registration 10
2 Loginstatus 1
3 Downloading 10
4 Redemming 1
5 Sharing 20
6 Refer 10
忠诚度详情表:
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
他已经完成了一次登录,所以他的登录状态点现在是 1 我想在下面的另一个table中更新这个点
预期输出:
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
我可以在 Linq 中使用 sql 触发器并找到解决方案吗?
用户可以使用 triggers
来完成这项工作。你可以看看this写一个
如何在加入 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
1,在您的数据引擎上
你可以使用触发器
2、你的程序
你可以编写一个机制。
通常trihger会伤害性能,我会使用计划B