Database Component hxj. Data (27th) (Field combination update)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.