This commit is contained in:
sunkaixuan
2023-09-28 16:11:56 +08:00
parent 30863330f2
commit c7725e4723

View File

@@ -17,16 +17,28 @@ namespace OrmTest
DbType = DbType.Sqlite, DbType = DbType.Sqlite,
ConnectionString = Config.ConnectionString3, ConnectionString = Config.ConnectionString3,
InitKeyType = InitKeyType.Attribute, InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true IsAutoCloseConnection = true
}); });
db.DbMaintenance.CreateDatabase(); db.DbMaintenance.CreateDatabase();
db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1 db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1
db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand(); db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand();
var list = db.Queryable<CodeFirstTable1>().ToList(); var list = db.Queryable<CodeFirstTable1>().ToList();
db = NewUnitTest.Db;
db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings()
{
SqliteCodeFirstEnableDefaultValue = true,
};
db.CodeFirst.InitTables<CodeFirstUnitafa>();
Console.WriteLine("#### CodeFirst end ####"); Console.WriteLine("#### CodeFirst end ####");
} }
} }
public class CodeFirstUnitafa
{
[SugarColumn(DefaultValue = "(strftime('%Y-%m-%d %H:%M:%S', 'now', 'localtime'))")]
public DateTime Name { get; set; }
[SugarColumn(DefaultValue = "1")]
public string Name2 { get; set; }
}
public class CodeFirstTable1 public class CodeFirstTable1
{ {
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)] [SugarColumn(IsIdentity = true, IsPrimaryKey = true)]