SqlSuger,清垃圾ORM實戰例子。
//添加引用 using SqlSugar; //在構造函數中實例化SqlSuger clinet = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = "......",//這里是數據庫連接字符串 DbType = SqlSugar.DbType.SqlServer, IsAutoCloseConnection = true }); //連表查詢 BaseUserCollection con = new BaseUserCollection(); var query = clinet.Queryable<Base_Users, Base_Roles>((t1, t2) => t1.RoleID == t2.RoleID).Select<Base_Role_User>(); if(query != null) { con.List = await query.ToPageListAsync(pageIndex, pageSize); con.Count = await query.CountAsync(); } return con; //插入數據 return await clinet.Insertable(security).ExecuteReturnIdentityAsync();
