NetTiers学习笔记07---查询类的使用
public void Test()
{
SqlFilterBuilder<ContractColumn> filter = new SqlFilterBuilder<ContractColumn>(); //test SqlFilterBuilder
//ParameterizedSqlFilterBuilder<ContractColumn> filter = new ParameterizedSqlFilterBuilder<ContractColumn>(); //test ParameterizedSqlFilterBuilder
filter.Junction = SqlUtil.AND;
filter.Append(ContractColumn.FContractPerson, "Jack , Ban , Tom"); //or jack or ban or tom
filter.Append(ContractColumn.FName, "*-02-01"); // like
filter.AppendIsNotNull(ContractColumn.FName); //is not null
filter.BeginGroup(SqlUtil.AND); //开始一个分组
filter.Junction = String.Empty; //"("后面没有and
filter.AppendIn(ContractColumn.FHouseId, "1,2,3,4"); //in
filter.Junction = SqlUtil.OR;
string begindate = new DateTime(2005, 1, 1).ToString();
string enddate = DateTime.Now.ToString();
filter.AppendRange(ContractColumn.FDate, begindate, enddate); //范围
filter.EndGroup(); //结束分组
string result = filter.ToString(); //test1
//SqlFilterParameterCollection result = filter.GetParameters(); //test2
}
{
SqlFilterBuilder<ContractColumn> filter = new SqlFilterBuilder<ContractColumn>(); //test SqlFilterBuilder
//ParameterizedSqlFilterBuilder<ContractColumn> filter = new ParameterizedSqlFilterBuilder<ContractColumn>(); //test ParameterizedSqlFilterBuilder
filter.Junction = SqlUtil.AND;
filter.Append(ContractColumn.FContractPerson, "Jack , Ban , Tom"); //or jack or ban or tom
filter.Append(ContractColumn.FName, "*-02-01"); // like
filter.AppendIsNotNull(ContractColumn.FName); //is not null
filter.BeginGroup(SqlUtil.AND); //开始一个分组
filter.Junction = String.Empty; //"("后面没有and
filter.AppendIn(ContractColumn.FHouseId, "1,2,3,4"); //in
filter.Junction = SqlUtil.OR;
string begindate = new DateTime(2005, 1, 1).ToString();
string enddate = DateTime.Now.ToString();
filter.AppendRange(ContractColumn.FDate, begindate, enddate); //范围
filter.EndGroup(); //结束分组
string result = filter.ToString(); //test1
//SqlFilterParameterCollection result = filter.GetParameters(); //test2
}
SqlFilterBuilder:
(fContractPerson = 'Jack' OR fContractPerson = 'Ban' OR fContractPerson = 'Tom') AND (fName LIKE '%-02-01') AND (fName IS NOT NULL) AND ( (fHouseID IN ('1','2','3','4')) OR (fDate >= '2005-1-1 0:00:00' AND fDate <= '2007-7-10 13:39:06') )
SqlFilterParameterBuilder:
(fContractPerson = @Param0 OR fContractPerson = @Param1 OR fContractPerson = @Param2) AND (fName LIKE @Param3) AND (fName IS NOT NULL) AND ((fHouseID IN (@Param4,@Param5,@Param6,@Param7)) OR (fDate >= @Param8 AND fDate <= @Param9))