Whereclipbuilder is a new class in version 1.7.2 that is used to create whereclip.
The previous version Whereclip was created 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);每增加一个条件都是生成一个新的WhereClip。
Use Whereclipbuilder as follows:
WhereClipBuilder wherebuilder = new WhereClipBuilder();
wherebuilder.And(Products._.ProductName.Contain("apple"));
wherebuilder.And(Products._.UnitPrice > 1);
wherebuilder.Or(Products._.CategoryID == 2);
Whereclipbuilder is to create new instances without adding conditions, thus reusing and saving 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: http://www.cnblogs.com/huxj/archive/2009/11/21/1607791.html