public IActionResult Get(int id, string tbName, string sql = null) { try { switch (id) { case 0: { return(Ok(DbContentPropertyNames)); } break; default: { //检查表名是否存在 if (!DbContentPropertyInfos.Exists(p => p.Name == tbName)) { throw new AggregateException("Table Name Not Found"); } //返表 Json数据 using (ResumeBrowingSystemV00Context db = new ResumeBrowingSystemV00Context()) { IList resultList = null; if ("Staffs" == tbName) { resultList = ExecuteSql <Staffs, ResumeBrowingSystemV00Context>(db, sql); } else if ("Experiences" == tbName) { resultList = ExecuteSql <Experiences, ResumeBrowingSystemV00Context>(db, sql); } else if ("UserInfo" == tbName) { resultList = ExecuteSql <UserInfo, ResumeBrowingSystemV00Context>(db, sql); } if (resultList == null) { throw new AggregateException("Sql Fail"); } return(Ok(resultList)); } } break; } } catch (Exception ex) { return(NotFound(ex.Message)); } }
/// <summary> /// 构造函数 /// </summary> public DataController() { this.DbContentPropertyInfos = new List <PropertyInfo>( typeof(ResumeBrowingSystemV00Context).GetProperties( BindingFlags.Instance | //包含实例成员 BindingFlags.Static | //静态成员 BindingFlags.Public | //公共成员 BindingFlags.DeclaredOnly //不包含继承成员 )); this.DbContentPropertyNames = DbContentPropertyInfos.ConvertAll <string>(t => t.Name); }