1 查询单行
DBInstance.DB.SingleOrDefault<CompanyInfo11>(id);
/// <summary> /// 根据id获取公司信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public static CompanyInfo11 GetCompanyById(int id) { return DBInstance.DB.SingleOrDefault<CompanyInfo11>(id); }
2 查询结果集
DBInstance.DB.Query<CompanyInfo11>("where 1=1 order by Cid desc").ToList()
/// <summary> /// 查询所有公司信息,按创建日期倒序 /// </summary> /// <returns>数据表格</returns> public List<CompanyInfo11> Load() { List<CompanyInfo11> companyList = null; companyList= DBInstance.DB.Query<CompanyInfo11>("where 1=1 order by Cid desc").ToList(); return companyList; }
3 根据条件查询结果集
/// <summary> /// 查询所有公司信息,根据参数 /// </summary> /// <returns>数据表格</returns> public List<CompanyInfo11> Load() { List<CompanyInfo11> companyList = null; companyList = DBInstance.DB.Query<CompanyInfo11>("where Cid>@0", 5).ToList();//第一个参数是@0,第二个参数是@1,等等 return companyList; }
时间: 2024-10-14 08:37:23