Catalog of this series
- CRL Rapid Development Framework Series tutorial One (Code First Data Sheet no need to care)
- CRL Rapid Development Framework Series Tutorial II (based on lambda expression query)
- CRL Rapid Development Framework Series Tutorial III (update data)
- CRL Rapid Development Framework Series Tutorial IV (delete data)
- CRL Rapid Development Framework Series tutorial five (using cache)
- CRL Rapid Development Framework Series Tutorial VI (Distributed cache solution)
- CRL Rapid Development Framework Series Tutorial VII (using transactions)
- CRL Rapid Development Framework Series tutorial eight (using Crl.package)
- CRL Rapid Development Framework Series Tutorial nine (Import/Export data)
- CRL Rapid Development Framework Series Tutorial 10 (Export object structure)
- CRL Rapid Development Framework Series Tutorial 11 (Big Data sub-database sub-table solutions)
- 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)