CRL Rapid Development Framework Series Tutorial III (update data)

Source: Internet
Author: User
Tags mongodb support

Catalog of this series
    1. CRL Rapid Development Framework Series tutorial One (Code First Data Sheet no need to care)
    2. CRL Rapid Development Framework Series Tutorial II (based on lambda expression query)
    3. CRL Rapid Development Framework Series Tutorial III (update data)
    4. CRL Rapid Development Framework Series Tutorial IV (delete data)
    5. CRL Rapid Development Framework Series tutorial five (using cache)
    6. CRL Rapid Development Framework Series Tutorial VI (Distributed cache solution)
    7. CRL Rapid Development Framework Series Tutorial VII (using transactions)
    8. CRL Rapid Development Framework Series tutorial eight (using Crl.package)
    9. CRL Rapid Development Framework Series Tutorial nine (Import/Export data)
    10. CRL Rapid Development Framework Series Tutorial 10 (Export object structure)
    11. CRL Rapid Development Framework Series Tutorial 11 (Big Data sub-database sub-table solutions)
    12. CRL Rapid Development Framework Series Tutorial 12 (MongoDB support)

Body

CRL update data is available in several ways, depending on preferences and actual scenario invocation

Only the modified properties are committed, and if the modification is 0, an exception is thrown

1. The format of the dictionary reference ( not recommended )

Crl. Paramecollection C = new CRL. Paramecollection (); c["ProductName"] = "product1"; Code.ProductDataManage.Instance.Update (b = b.id = = 4, c);

2. by anonymous Object

Code.ProductDataManage.Instance.Update (b = b.id = = 4, new {ProductName = "product1"});

3. Update by Object variance (when object is not created by query) recommended

This is a manual notification of which properties have been changed to modify only the changed properties when updating

            var p = new Code.productdata () {Id = 4};            When manually modifying a value, specify that the property be modified to be recognized at update time, in the following forms            P.change (b = b.barcode);//indicates that the value has been changed            P.change (b = B.barcode, "123") ;//By parameter assignment            P.change (b = = B.barcode = = "123");//Assign value by expression            p.cumulation (b = b.productname, "1");//means accumulate by field            Code.ProductDataManage.Instance.Update (b = b.id = = 4, p);//Specify Query update

4. When the object is a query creation

After the property is changed, the CRL automatically recognizes which changes have been made

            p = Code.ProductDataManage.Instance.QueryItem (b = b.id > 0);            P.userid + = 1;//will only update UserId            p.productname = "2342342";            Code.ProductDataManage.Instance.Update (P);//update by primary key, primary key value is required

5. Associating updates with a full query

Associate updates in the form of SQL

The right $ symbol represents the associated table

var query = Code.OrderManage.Instance.GetLambdaQuery ();            Query. Join<code.productdata> ((a, b) = a.ID = = b.id && b.number >);            c = new CRL. Paramecollection ();            c["UserId"] = "$UserId";//order.userid=product.userid            c["Remark"] = "2222";//order.remark=2222            Code.OrderManage.Instance.Update (query, c);            Equivalent statement for update order set userid=productdata.userid,remark= ' 2222 ' from Productdata where order.id=productdata.id and Productdata.number<10

CRL Rapid Development Framework Series Tutorial III (update data)

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.