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

@@ -147,6 +147,7 @@
<Compile Include="OldTest\UnitTest\Setting\MapTable.cs" />
<Compile Include="OldTest\UnitTest\Update.cs" />
<Compile Include="Models\CarType.cs" />
<Compile Include="UnitTest\UCodeFirst.cs" />
<Compile Include="UnitTest\UAdo.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,25 @@
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>();
}
public class UnitCodeTest1
{
[SqlSugar.SugarColumn(IndexGroupNameList = new string[] { "group1" })]
public int Id { get; set; }
[SqlSugar.SugarColumn(DefaultValue="getdate()", IndexGroupNameList =new string[] {"group1" } )]
public DateTime? CreateDate { get; set; }
}
}
}