Add db.Saveable

This commit is contained in:
sunkaixuan
2019-01-20 18:53:29 +08:00
parent a21a54098c
commit afdec7845d
8 changed files with 253 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
using OrmTest.Demo;
using OrmTest.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
public class IInsertOrUpdate : DemoBase
{
public static void Init()
{
var db = GetInstance();
var entity= db.Insertable<Student>(new Student() { Name = "abc" }).ExecuteReturnEntity();
db.Saveable<Student>(entity).ExecuteReturnEntity();
//UPDATE [STudent] SET
//[SchoolId]=@SchoolId,[Name]=@Name,[CreateTime]=@CreateTime WHERE[Id] = @Id
db.Saveable<Student>(new Student() { Name="" }).ExecuteReturnEntity();
// INSERT INTO[STudent]
//([SchoolId],[Name],[CreateTime])
// VALUES
//(@SchoolId, @Name, @CreateTime); SELECT SCOPE_IDENTITY();
db.Saveable<Student>(new Student() { Name = "" }).InsertColumns(it=>it.Name).ExecuteReturnEntity();
db.Saveable<Student>(new Student() { Name = "" }).InsertIgnoreColumns(it => it.SchoolId).ExecuteReturnEntity();
db.Saveable<Student>(entity).UpdateIgnoreColumns(it=>it.SchoolId).ExecuteReturnEntity();
db.Saveable<Student>(entity).UpdateColumns(it=>new { it.Name,it.CreateTime }).ExecuteReturnEntity();
db.Saveable<Student>(new List<Student>() {
entity,
new Student() { Name = "" }
}).ExecuteCommand();
}
}
}

View File

@@ -60,6 +60,7 @@ namespace OrmTest
Demo.ExtEntity.Init();
Demo.VersionValidation.Init();
Demo.Delete.Init();
Demo.IInsertOrUpdate.Init();
}
}
}

View File

@@ -58,6 +58,7 @@
<Compile Include="BugTest\BugModels\tLogonHistoryModel.cs" />
<Compile Include="BugTest\BugModels\VipAccountsModel.cs" />
<Compile Include="BugTest\BugModels\VipBenefitsModel.cs" />
<Compile Include="Demos\IInsertOrUpdate.cs" />
<Compile Include="Models\Brand.cs" />
<Compile Include="BugTest\Bug1.cs" />
<Compile Include="Models\VendorAndBrand.cs" />