Add Insertable.CallEntityMethod

Add Updateable.CallEntityMethod
This commit is contained in:
SUNKAIXUAN
2021-03-02 19:58:42 +08:00
parent 6bc53c1239
commit 6b4e0b4f20
8 changed files with 98 additions and 0 deletions

View File

@@ -80,6 +80,7 @@
<Compile Include="UnitTest\Test01.cs" />
<Compile Include="UnitTest\UEnum.cs" />
<Compile Include="UnitTest\UFilter.cs" />
<Compile Include="UnitTest\UInsert2.cs" />
<Compile Include="UnitTest\UInsert.cs" />
<Compile Include="UnitTest\UQueryable2.cs" />
<Compile Include="UnitTest\UQueue.cs" />

View File

@@ -33,6 +33,7 @@ namespace OrmTest
{
Filter();
Insert();
Insert2();
Enum();
Tran();
Queue();

View File

@@ -0,0 +1,43 @@
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 Insert2()
{
var db = Db;
db.CodeFirst.InitTables<UnitInsertMethod>();
db.Insertable(new UnitInsertMethod() { Name = "1" }).CallEntityMethod(it=>it.Create()).ExecuteCommand();
db.Insertable(new UnitInsertMethod() { Name = "2" }).CallEntityMethod(it => it.Create("admin")).ExecuteCommand();
db.Updateable(new UnitInsertMethod() {Id=1, Name = "1" }).CallEntityMethod(it => it.Create()).ExecuteCommand();
db.Updateable(new UnitInsertMethod() { Name = "1" }).CallEntityMethod(it => it.Create("admint")).ExecuteCommand();
}
public class UnitInsertMethod
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
public DateTime Time { get; set; }
[SqlSugar.SugarColumn(IsNullable =true)]
public string UserId { get; set; }
public void Create()
{
this.Time = DateTime.Now;
this.UserId = "1";
}
public void Create(string a)
{
this.Time = DateTime.Now;
this.UserId = a;
}
}
}
}