public override IEnumerable <T> GetByIds <T>(object ids, string returnFields = null) { var sqls = GetDapperSqls(typeof(T)); if (string.IsNullOrEmpty(sqls.KeyName)) { throw new Exception("表[" + sqls.TableName + "]没有主键"); } if (DapperCommon.ObjectIsEmpty(ids)) { return(Enumerable.Empty <T>()); } Dapper.DynamicParameters dpar = new Dapper.DynamicParameters(); dpar.Add("@ids", ids); if (string.IsNullOrEmpty(returnFields)) { return(Query <T>(sqls.GetByIdsSql, dpar)); } else { string sql = string.Format("SELECT {0} FROM [{1}] WHERE [{2}] IN @ids", returnFields, sqls.TableName, sqls.KeyName); return(Query <T>(sql, dpar)); } }
public override int DeleteByIds <T>(object ids) { var sqls = GetDapperSqls(typeof(T)); if (string.IsNullOrEmpty(sqls.KeyName)) { throw new Exception("表[" + sqls.TableName + "]没有主键"); } if (DapperCommon.ObjectIsEmpty(ids)) { return(0); } Dapper.DynamicParameters dpar = new Dapper.DynamicParameters(); dpar.Add("@ids", ids); return(Execute(sqls.DeleteByIdsSql, dpar)); }
public override IEnumerable <T> GetByIdsWhichField <T>(object ids, string whichField, string returnFields = null) { var sqls = GetDapperSqls(typeof(T)); if (DapperCommon.ObjectIsEmpty(ids)) { return(Enumerable.Empty <T>()); } Dapper.DynamicParameters dpar = new Dapper.DynamicParameters(); dpar.Add("@ids", ids); if (string.IsNullOrEmpty(returnFields)) { returnFields = sqls.AllFields; } string sql = string.Format("SELECT {0} FROM [{1}] WHERE [{2}] IN @ids", returnFields, sqls.TableName, whichField); return(Query <T>(sql, dpar)); }