Wheredia builder is a new class added in version 1.7.2 to create whereclip.
Create whereclip with multiple conditions in the previous version as follows:
WhereClip where = WhereClip.All;where = where.And(Products._.ProductName.Contain("apple"));where = where.And(Products._.UnitPrice > 1);where = where.Or(Products._.CategoryID == 2);
Each added condition generates a new whereclip.
Wheredia builder is used as follows:
WhereClipBuilder wherebuilder = new WhereClipBuilder();wherebuilder.And(Products._.ProductName.Contain("apple"));wherebuilder.And(Products._.UnitPrice > 1);wherebuilder.Or(Products._.CategoryID == 2);
Wheredia builder creates new instances without adding conditions to accumulate conditions, so as to be reused and save resources.
Specific use:
Northwind.From<Products>() .Where(wherebuilder.ToWhereClip()) .ToList();
Generated SQL:
Text:
SELECT * FROM [Products]
WHERE (((([Products].[ProductName] LIKE @jtioerxooyxzyvsj) AND ([Products].[UnitPrice] > @txdupnwvhfznviqj))
OR ([Products].[CategoryID] = @iqgkjykstppcrqsq)))
Parameters:
@jtioerxooyxzyvsj[String] = %apple%
@txdupnwvhfznviqj[Int32] = 1
@iqgkjykstppcrqsq[Int32] = 2
Download