Service语法
//根据某属性获取
public async Task<AreaEntity> GetEntityByAreaCode(string areaCode) { //todo根据……获取 return await this.BaseRepository().FindEntity<AreaEntity>(p => p.AreaCode == areaCode); }
获取最近一条
/// <summary> /// 根据手机号码获取最新的短信记录 /// </summary> /// <param name="Mobile"></param> /// <returns></returns> public async Task<List<VerifiyCodeEntity>> GetLastVerifity(string Mobile,string code) { var resu = ""; var parm = new VerifiyCodeParam(); parm.Mobile = Mobile; parm.Code = code; var sql = new StringBuilder(); var op = ListFilter(parm, sql, " BaseCreateTime desc",1); var list = await this.BaseRepository().FindList<VerifiyCodeEntity>(sql.ToString(), op.ToArray()); return list.ToList(); }
private List<DbParameter> ListFilter(VerifiyCodeParam param, StringBuilder strSql,string orderBy="",int limit=0) { strSql.Append(@"SELECT BaseCreateTime,Mobile,Code,TypeId from sysverifiycode WHERE 1 = 1"); var parameter = new List<DbParameter>(); if (param != null) { if (!string.IsNullOrEmpty(param.Code)) { strSql.Append(" AND Code = @Code"); parameter.Add(DbParameterExtension.CreateDbParameter("@Code", param.Code)); } if (param.State > 0) { strSql.Append(" AND State = @State"); parameter.Add(DbParameterExtension.CreateDbParameter("@State", param.State)); } if (!string.IsNullOrEmpty(param.Mobile)) { strSql.Append(" AND Mobile = @Mobile"); parameter.Add(DbParameterExtension.CreateDbParameter("@Mobile", param.Mobile )); } if (!orderBy.IsEmpty()) { strSql.Append(" order by " + orderBy); } if (!limit.IsEmpty()) { strSql.Append(" limit "+limit); } } return parameter; }