sqlsugar這個框架查詢數據速度很快, 接近原生, 所以就決定用它咯 它和ef一樣 有codefirst和dbfirst
不多說 直接上代碼
首先 寫連接數據庫的類
public class SqlSugarInstance { public static SqlSugarClient GetInstance() { SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString=@"xxxxxx", //必填 DbType = DbType.SqlServer, //必填 IsAutoCloseConnection = true, InitKeyType = InitKeyType.Attribute // Attribute用於DbFirst 從數據庫生成model的
//InitKeyType = InitKeyType.SystemTable SystemTable用於Codefirst 從model庫生成數據庫表的
}); return db; } }
然后就是代碼了
using (SqlSugarClient db =SqlSugarInstance.GetInstance()) { try { // db.CodeFirst.InitTables(typeof(xxxx)); db.DbFirst.Where("xxxx").CreateClassFile("D:\\Demo\\2.txt");//生成文件的·地址 } catch (Exception ex) { throw; } }
好了 差不多就是這樣了 很方便快捷 生成文件的地址也可以放在你項目文件指定的地址下 不過沒試過 不知道能不能成功 哈哈哈