CodeFirst adds database index and default value

This commit is contained in:
sunkaixuan
2019-05-26 17:07:09 +08:00
parent 70f7c85e46
commit 7ef0bce3d4
18 changed files with 398 additions and 132 deletions

View File

@@ -116,6 +116,7 @@
<Compile Include="OldTests\UnitTest\Update.cs" />
<Compile Include="UnitTest\Main.cs" />
<Compile Include="UnitTest\UAdo.cs" />
<Compile Include="UnitTest\UCodeFirst.cs" />
<Compile Include="UnitTest\UJson.cs" />
<Compile Include="UnitTest\Updateable.cs" />
<Compile Include="UnitTest\UQueryable.cs" />

View File

@@ -25,6 +25,7 @@ namespace OrmTest
});
public static void Init()
{
CodeFirst();
Updateable();
Json();
Ado();

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
public static void CodeFirst()
{
if (Db.DbMaintenance.IsAnyTable("UnitCodeTest1", false))
Db.DbMaintenance.DropTable("UnitCodeTest1");
Db.CodeFirst.InitTables<UnitCodeTest1>();
Db.CodeFirst.InitTables<UnitCodeTest1>();
}
public class UnitCodeTest1
{
[SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })]
public int Id { get; set; }
[SqlSugar.SugarColumn(DefaultValue = "now()", IndexGroupNameList = new string[] { "group1" })]
public DateTime? CreateDate { get; set; }
}
}
}