LLBLGen update table with join
Table1
id | Name |
1 | xxx |
2 |
ooo |
Table2
Table1Id | Table1Name | Column1 | Column2 | Column3 |
1 | sss | xxxx | xxxx | xxxx |
2 | ddd | xxxx | xxxx | xxxx |
2 | ddd | xxxx | xxxx | xxxx |
更新Table1的Name到Table2
/* * Update t2 * Set t2.Table1Name = t1.Name * From Table2 t2 * Join Table1 t1 on t1.Id = t2.Table1Id * Where t1.Name <> t2.Table1Name */ // 兩個table沒有創建foreign key, 需要先create custom relation EntityRelation entityRelation = new EntityRelation(Table1Fields.Id, Table2Fields.Table1Id, RelationType.OneToMany); IRelationCollection relation = new RelationCollection(); relation.Add(entityRelation, JoinHint.Inner); IPredicateExpression filter = new PredicateExpression(); filter.Add(Table2Fields.Table1Name != Table1Fields.Name); Table2Entity updater = new Table2Entity(); updater.Fields[(int)Table2FieldIndex.Table1Name].ExpressionToApply = new Expression(Table1Fields.Name); Table2Collection updatedCollection = new Table2Collection(); updatedCollection.UpdateMulti(updater, filter, relation);