Hxj. Data v1.5.1 supports field combination update.
Example: Update table set A = B + C
Update table set a = a + 1
(+,-, *,/, %) And so on.
The following is an example. (The example only serves to test the effect and has no practical significance)
Example 1,
DbSession.Default.Update<Products>(Products._.UnitPrice, Products._.ReorderLevel + Products._.UnitPrice, Products._.ProductID == 1);
The generated SQL statement is as follows:
Text:
UPDATE [Products] SET [UnitPrice]=[Products].[ReorderLevel] + [Products].[UnitPrice]
WHERE [Products].[ProductID] = @mjpxqimmtmiyguvv
Parameters:
@mjpxqimmtmiyguvv[Int32] = 1
Update the value of the unitprice field to the value of the reorderlevel field added to unitprice.
Example 2,
DbSession.Default.Update<Products>(Products._.UnitPrice, Products._.UnitPrice + 1, Products._.ProductID == 1);
The generated SQL statement is as follows:
Text:
UPDATE [Products] SET [UnitPrice]=[Products].[UnitPrice] + @tszvynxwnukkjuzj
WHERE [Products].[ProductID] = @anuixieadujzvvka
Parameters:
@tszvynxwnukkjuzj[Int32] = 1
@anuixieadujzvvka[Int32] = 1
Add the value of the unitprice field to 1.
Example 3,
using (DbTrans trans = DbSession.Default.BeginTransaction()){ trans.Update<Products>(Products._.UnitPrice, Products._.UnitPrice + 1.4, Products._.ProductID == 1); trans.Update<Products>(Products._.UnitPrice, Products._.UnitPrice - 2, Products._.ProductID == 2); trans.Commit();}
Generated SQL:
Text:
UPDATE [Products] SET [UnitPrice]=[Products].[UnitPrice] + @zeylmhakevldbgfn
WHERE [Products].[ProductID] = @enbemtqnigeugdej
Parameters:
@zeylmhakevldbgfn[Double] = 1.4
@enbemtqnigeugdej[Int32] = 1
Text:
UPDATE [Products] SET [UnitPrice]=[Products].[UnitPrice] - @vypfmbnjgdpeakqm
WHERE [Products].[ProductID] = @dqwlfxqjconzrqa
Parameters:
@vypfmbnjgdpeakqm[Int32] = 2
@dqwlfxqjconzrqa[Int32] = 2
Update a transaction.
However, it should be noted that the value of this addition or subtraction must be consistent with the field type, and must be converted manually first.