mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-27 11:19:15 +08:00
Add db.Saveable
This commit is contained in:
40
Src/Asp.Net/SqlServerTest/Demos/IInsertOrUpdate.cs
Normal file
40
Src/Asp.Net/SqlServerTest/Demos/IInsertOrUpdate.cs
Normal 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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@ namespace OrmTest
|
||||
Demo.ExtEntity.Init();
|
||||
Demo.VersionValidation.Init();
|
||||
Demo.Delete.Init();
|
||||
Demo.IInsertOrUpdate.Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user