topcss/my-notes

petapoco

Opened this issue · 1 comments

参照
https://www.cnblogs.com/dongh/p/6802931.html

var sql = PetaPoco.Sql.Builder
.Append("SELECT a.* FROM AAA a RIGHT JOIN BBB b ON a.AID = b.TID ")
.Append(" WHERE a.XCSJ BETWEEN @0 AND @1", kssj, jzsj);
 
if (!string.IsNullOrEmpty(SEX))
{
    sql.Append(" and a.TID in (Select TKEY from TTT where SEX=@0 and TABLENAME=@1 AND SEX IS NOT NULL) ", SEX, "");
}

var dal = new PetaPoco.Database(DbConnection.BllConnection);

PetaPoco.Page<dynamic> list = dal.Page<dynamic>(1, 1000, sql);

// 使用Where in
var tagsToFind = new string[] { "SqlServer", "IIS" };
var sql = PetaPoco.Sql.Builder.Select("*").From("Tags").Where("Name in (@tags)", new { tags = tagsToFind });
var result = db.Query<Tag>(sql);

注意:
很多错误的查询,都是因为条件字段不在查询字段中引起的。