mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update demo
This commit is contained in:
parent
b6a747dbf2
commit
f0cffe712b
@ -6,10 +6,26 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Setting up the database name does not require you to create the database
|
||||
/// 设置好数据库名不需要你去手动建库
|
||||
/// </summary>
|
||||
public class Config
|
||||
{
|
||||
/// <summary>
|
||||
/// Account have permission to create database
|
||||
/// 用有建库权限的数据库账号
|
||||
/// </summary>
|
||||
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql";
|
||||
public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=haosql";
|
||||
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=haosql";
|
||||
/// <summary>
|
||||
/// Account have permission to create database
|
||||
/// 用有建库权限的数据库账号
|
||||
/// </summary>
|
||||
public static string ConnectionString2 = "server=localhost;Database=SqlSugar4xTest2;Uid=root;Pwd=haosql";
|
||||
/// <summary>
|
||||
/// Account have permission to create database
|
||||
/// 用有建库权限的数据库账号
|
||||
/// </summary>
|
||||
public static string ConnectionString3 = "server=localhost;Database=SqlSugar4xTest3;Uid=root;Pwd=haosql";
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data.Linq.Mapping;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -17,7 +17,34 @@ namespace OrmTest
|
||||
DbContext();//Optimizing SqlSugarClient usage
|
||||
SingletonPattern();//Singleten Pattern
|
||||
DistributedTransactionExample();
|
||||
CustomAttribute();
|
||||
MasterSlave();//Read-write separation
|
||||
CustomAttribute();
|
||||
}
|
||||
|
||||
private static void MasterSlave()
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### MasterSlave Start ####");
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,//Master Connection
|
||||
DbType = DbType.SqlServer,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
SlaveConnectionConfigs = new List<SlaveConnectionConfig>() {
|
||||
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 } ,
|
||||
new SlaveConnectionConfig() { HitRate=10, ConnectionString=Config.ConnectionString2 }
|
||||
}
|
||||
});
|
||||
db.Aop.OnLogExecuted = (s, p) =>
|
||||
{
|
||||
Console.WriteLine(db.Ado.Connection.ConnectionString);
|
||||
};
|
||||
Console.WriteLine("Master:");
|
||||
db.Insertable(new Order() { Name = "abc", CustomId = 1, CreateTime = DateTime.Now }).ExecuteCommand();
|
||||
Console.WriteLine("Slave:");
|
||||
db.Queryable<Order>().First();
|
||||
Console.WriteLine("#### MasterSlave End ####");
|
||||
}
|
||||
|
||||
private static void SqlSugarClient()
|
||||
@ -26,7 +53,7 @@ namespace OrmTest
|
||||
Console.WriteLine("#### SqlSugarClient Start ####");
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -40,16 +67,18 @@ namespace OrmTest
|
||||
}
|
||||
});
|
||||
|
||||
//if no exist create datebase SQLSUGAR4XTEST (bin/database/)
|
||||
//If no exist create datebase
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
|
||||
//Use db
|
||||
//Use db query
|
||||
var dt = db.Ado.GetDataTable("select 1");
|
||||
|
||||
//create table OrderDetail
|
||||
db.CodeFirst.InitTables(typeof(OrderItem));
|
||||
//Create tables
|
||||
db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order));
|
||||
var id = db.Insertable(new Order() { Name = "order1", CustomId = 1, Price = 0, CreateTime = DateTime.Now }).ExecuteReturnIdentity();
|
||||
|
||||
db.Insertable(new OrderItem() { OrderId = 1, Price = 0 }).ExecuteCommand();
|
||||
//Insert data
|
||||
db.Insertable(new OrderItem() { OrderId = id, Price = 0, CreateTime=DateTime.Now }).ExecuteCommand();
|
||||
Console.WriteLine("#### SqlSugarClient End ####");
|
||||
|
||||
}
|
||||
@ -63,7 +92,7 @@ namespace OrmTest
|
||||
|
||||
DbContext context = new DbContext();
|
||||
|
||||
context.Db.CodeFirst.InitTables<Order, OrderItem, Custom>();//Create Tables
|
||||
context.Db.CodeFirst.InitTables<Order, OrderItem,Custom>();//Create Tables
|
||||
;
|
||||
var orderDb = context.OrderDb;
|
||||
|
||||
@ -91,10 +120,10 @@ namespace OrmTest
|
||||
|
||||
//Delete
|
||||
orderDb.Delete(insertObj);
|
||||
orderDb.DeleteById(1);
|
||||
orderDb.DeleteById(new int[] { 1, 2 });
|
||||
orderDb.Delete(it => it.Id == 1);
|
||||
orderDb.AsDeleteable().Where(it => it.Id == 1).ExecuteCommand();
|
||||
orderDb.DeleteById(11111);
|
||||
orderDb.DeleteById(new int[] { 1111, 2222 });
|
||||
orderDb.Delete(it => it.Id == 1111);
|
||||
orderDb.AsDeleteable().Where(it => it.Id == 1111).ExecuteCommand();
|
||||
|
||||
//Update
|
||||
orderDb.Update(insertObj);
|
||||
@ -117,7 +146,7 @@ namespace OrmTest
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
ConfigureExternalServices = new ConfigureExternalServices()
|
||||
@ -142,10 +171,10 @@ namespace OrmTest
|
||||
}
|
||||
}
|
||||
});
|
||||
db.CodeFirst.InitTables<MyCustomAttributeTable>();//Create Table
|
||||
db.CodeFirst.InitTables<AttributeTable>();//Create Table
|
||||
|
||||
db.Insertable(new MyCustomAttributeTable() { Id = Guid.NewGuid().ToString(), Name = "Name" }).ExecuteCommand();
|
||||
var list = db.Queryable<MyCustomAttributeTable>().ToList();
|
||||
db.Insertable(new AttributeTable() { Id = Guid.NewGuid().ToString(), Name = "Name" }).ExecuteCommand();
|
||||
var list = db.Queryable<AttributeTable>().ToList();
|
||||
|
||||
Console.WriteLine("#### Custom Attribute End ####");
|
||||
}
|
||||
@ -180,7 +209,7 @@ namespace OrmTest
|
||||
new ConnectionConfig()
|
||||
{
|
||||
ConfigId = 1,
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -193,7 +222,121 @@ namespace OrmTest
|
||||
|
||||
private static void DistributedTransactionExample()
|
||||
{
|
||||
//see SqlServerTest
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### Distributed TransactionExample Start ####");
|
||||
SqlSugarClient db = new SqlSugarClient(new List<ConnectionConfig>()
|
||||
{
|
||||
new ConnectionConfig(){ ConfigId="1", DbType=DbType.SqlServer, ConnectionString=Config.ConnectionString,InitKeyType=InitKeyType.Attribute,IsAutoCloseConnection=true },
|
||||
new ConnectionConfig(){ ConfigId="2", DbType=DbType.SqlServer, ConnectionString=Config.ConnectionString2 ,InitKeyType=InitKeyType.Attribute ,IsAutoCloseConnection=true}
|
||||
});
|
||||
|
||||
//use db1
|
||||
db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem));//
|
||||
db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||
Console.WriteLine(db.CurrentConnectionConfig.DbType + ":" + db.Queryable<Order>().Count());
|
||||
|
||||
//use db2
|
||||
db.ChangeDatabase("2");
|
||||
db.DbMaintenance.CreateDatabase();//Create Database2
|
||||
db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem));
|
||||
db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand();
|
||||
Console.WriteLine(db.CurrentConnectionConfig.DbType + ":" + db.Queryable<Order>().Count());
|
||||
|
||||
// Example 1
|
||||
Console.WriteLine("Example 1");
|
||||
try
|
||||
{
|
||||
db.BeginTran();
|
||||
|
||||
db.ChangeDatabase("1");//use db1
|
||||
db.Deleteable<Order>().ExecuteCommand();
|
||||
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
|
||||
db.ChangeDatabase("2");//use db2
|
||||
db.Deleteable<Order>().ExecuteCommand();
|
||||
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
|
||||
throw new Exception();
|
||||
db.CommitTran();
|
||||
}
|
||||
catch
|
||||
{
|
||||
db.RollbackTran();
|
||||
Console.WriteLine("---Roll back");
|
||||
db.ChangeDatabase("1");//use db1
|
||||
Console.WriteLine(db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
|
||||
db.ChangeDatabase("2");//use db2
|
||||
Console.WriteLine(db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Example 2
|
||||
Console.WriteLine("Example 2");
|
||||
|
||||
var result=db.UseTran(() =>
|
||||
{
|
||||
|
||||
db.ChangeDatabase("1");//use db1
|
||||
db.Deleteable<Order>().ExecuteCommand();
|
||||
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
|
||||
db.ChangeDatabase("2");//use db2
|
||||
db.Deleteable<Order>().ExecuteCommand();
|
||||
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
throw new Exception("");
|
||||
|
||||
});
|
||||
if (result.IsSuccess == false) {
|
||||
Console.WriteLine("---Roll back");
|
||||
db.ChangeDatabase("1");//use db1
|
||||
Console.WriteLine(db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
|
||||
db.ChangeDatabase("2");//use db2
|
||||
Console.WriteLine(db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
}
|
||||
|
||||
// Example 3
|
||||
Console.WriteLine("Example 3");
|
||||
|
||||
var result2 = db.UseTranAsync(() =>
|
||||
{
|
||||
|
||||
db.ChangeDatabase("1");//use db1
|
||||
db.Deleteable<Order>().ExecuteCommand();
|
||||
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
|
||||
db.ChangeDatabase("2");//use db2
|
||||
db.Deleteable<Order>().ExecuteCommand();
|
||||
Console.WriteLine("---Delete all " + db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
throw new Exception("");
|
||||
|
||||
});
|
||||
result2.Wait();
|
||||
if (result.IsSuccess == false)
|
||||
{
|
||||
Console.WriteLine("---Roll back");
|
||||
db.ChangeDatabase("1");//use sqlserver
|
||||
Console.WriteLine(db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
|
||||
db.ChangeDatabase("2");//use mysql
|
||||
Console.WriteLine(db.CurrentConnectionConfig.DbType);
|
||||
Console.WriteLine(db.Queryable<Order>().Count());
|
||||
}
|
||||
|
||||
Console.WriteLine("#### Distributed TransactionExample End ####");
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,7 +352,7 @@ namespace OrmTest
|
||||
Db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
AopEvents = new AopEvents()
|
||||
@ -243,7 +386,7 @@ namespace OrmTest
|
||||
Db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
AopEvents = new AopEvents()
|
||||
|
@ -41,7 +41,7 @@ namespace OrmTest
|
||||
var getByWhere = db.Queryable<Order>().Where(it => it.Id == 1 || it.Name == "a").ToList();
|
||||
var getByWhere2 = db.Queryable<Order>().Where(it => it.Id == DateTime.Now.Year).ToList();
|
||||
var getByFuns = db.Queryable<Order>().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
|
||||
var getByFuns2 = db.Queryable<Order>().GroupBy(it=>it.Name).Select(it=>SqlFunc.AggregateDistinctCount(it.Price)).ToList();
|
||||
var getByFuns2 = db.Queryable<Order>().GroupBy(it => it.Name).Select(it => SqlFunc.AggregateDistinctCount(it.Price)).ToList();
|
||||
Console.WriteLine("#### Examples End ####");
|
||||
}
|
||||
|
||||
@ -142,13 +142,43 @@ namespace OrmTest
|
||||
db.Insertable(new Tree() { Id = 2, Name = "root" }).ExecuteCommand();
|
||||
db.Insertable(new Tree() { Id = 22, Name = "child3", ParentId = 2 }).ExecuteCommand();
|
||||
|
||||
var list=db.Queryable<Tree>()
|
||||
// Same property name mapping,Both entities have parentId
|
||||
var list = db.Queryable<Tree>().Mapper(it => it.Parent, it => it.ParentId).ToList();
|
||||
|
||||
|
||||
//If both entities have parentId, I don't want to associate with parentId.
|
||||
var list1 =db.Queryable<Tree>()
|
||||
//parent=(select * from parent where id=it.parentid)
|
||||
.Mapper(it=>it.Parent,it=>it.ParentId, it=>it.Parent.Id)
|
||||
//Child=(select * from parent where ParentId=it.id)
|
||||
.Mapper(it => it.Child, it => it.Id, it => it.Parent.ParentId)
|
||||
.ToList();
|
||||
//one to one
|
||||
var list2 = db.Queryable<OrderItemInfo>().Mapper(it => it.Order, it => it.OrderId).ToList();
|
||||
|
||||
//one to many
|
||||
var list3 = db.Queryable<Order>().Mapper(it => it.Items, it => it.Items.First().OrderId).ToList();
|
||||
|
||||
//many to many
|
||||
db.CodeFirst.InitTables<A, B, ABMapping>();
|
||||
|
||||
db.Insertable(new A() { Name = "A" }).ExecuteCommand();
|
||||
db.Insertable(new B() { Name = "B" }).ExecuteCommand();
|
||||
db.Insertable(new ABMapping() { AId = 1, BId = 1 }).ExecuteCommand();
|
||||
|
||||
var list4 = db.Queryable<ABMapping>()
|
||||
.Mapper(it => it.A, it => it.AId)
|
||||
.Mapper(it => it.B, it => it.BId).ToList();
|
||||
|
||||
//Manual mode
|
||||
var result = db.Queryable<OrderInfo>().Take(10).Select<ViewOrder>().Mapper((itemModel, cache) =>
|
||||
{
|
||||
var allItems = cache.Get(orderList => {
|
||||
var allIds = orderList.Select(it => it.Id).ToList();
|
||||
return db.Queryable<OrderItem>().Where(it => allIds.Contains(it.OrderId)).ToList();//Execute only once
|
||||
});
|
||||
itemModel.Items = allItems.Where(it => it.OrderId==itemModel.Id).ToList();//Every time it's executed
|
||||
}).ToList();
|
||||
|
||||
Console.WriteLine("#### End Start ####");
|
||||
}
|
||||
@ -159,9 +189,9 @@ namespace OrmTest
|
||||
Console.WriteLine("#### No Entity Start ####");
|
||||
var db = GetInstance();
|
||||
|
||||
var list = db.Queryable<dynamic>().AS("`order` ").Where("id=id", new { id = 1 }).ToList();
|
||||
var list = db.Queryable<dynamic>().AS("order ").Where("id=id", new { id = 1 }).ToList();
|
||||
|
||||
var list2 = db.Queryable<dynamic>("o").AS("`order`").AddJoinInfo("OrderDetail", "i", "o.id=i.OrderId").Where("id=id", new { id = 1 }).Select("o.*").ToList();
|
||||
var list2 = db.Queryable<dynamic>("o").AS("order").AddJoinInfo("OrderDetail", "i", "o.id=i.OrderId").Where("id=id", new { id = 1 }).Select("o.*").ToList();
|
||||
Console.WriteLine("#### No Entity End ####");
|
||||
}
|
||||
|
||||
@ -222,7 +252,7 @@ namespace OrmTest
|
||||
//id=@id
|
||||
var list4 = db.Queryable<Order>().Where("id=@id", new { id = 1 }).ToList();
|
||||
//id=@id or name like '%'+@name+'%'
|
||||
var list5 = db.Queryable<Order>().Where("id=@id or name like '%'||@name||'%' ", new { id = 1, name = "jack" }).ToList();
|
||||
var list5 = db.Queryable<Order>().Where("id=@id or name like '%'+@name+'%' ", new { id = 1, name = "jack" }).ToList();
|
||||
|
||||
|
||||
|
||||
@ -293,7 +323,7 @@ namespace OrmTest
|
||||
{
|
||||
return new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.MySql,
|
||||
DbType = SqlSugar.DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
|
@ -16,7 +16,7 @@ namespace OrmTest
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -63,8 +63,8 @@ namespace OrmTest
|
||||
var result7 = db.Updateable<Order>(it => new Order() { Name = "a", CreateTime = DateTime.Now }).Where(it => it.Id == 11).ExecuteCommand();
|
||||
var result71 = db.Updateable<Order>().SetColumns(it => new Order() { Name = "a", CreateTime = DateTime.Now }).Where(it => it.Id == 11).ExecuteCommand();
|
||||
//only update name
|
||||
var result8 = db.Updateable<Order>(it => it.Name == "Name" + 1).Where(it => it.Id == 1).ExecuteCommand();
|
||||
var result81 = db.Updateable<Order>().SetColumns(it => it.Name == "Name" + 1).Where(it => it.Id == 1).ExecuteCommand();
|
||||
var result8 = db.Updateable<Order>(it => it.Name == "Name" + "1").Where(it => it.Id == 1).ExecuteCommand();
|
||||
var result81 = db.Updateable<Order>().SetColumns(it => it.Name == "Name" + "1").Where(it => it.Id == 1).ExecuteCommand();
|
||||
//
|
||||
|
||||
|
||||
@ -73,13 +73,13 @@ namespace OrmTest
|
||||
/*** 3.by Dictionary ***/
|
||||
var dt = new Dictionary<string, object>();
|
||||
dt.Add("id", 1);
|
||||
dt.Add("name", null);
|
||||
dt.Add("name", "abc");
|
||||
dt.Add("createTime", DateTime.Now);
|
||||
var dtList = new List<Dictionary<string, object>>();
|
||||
dtList.Add(dt);
|
||||
|
||||
var t66 = db.Updateable(dt).AS("student").WhereColumns("id").ExecuteCommand();
|
||||
var t666 = db.Updateable(dtList).AS("student").WhereColumns("id").ExecuteCommand();
|
||||
var t66 = db.Updateable(dt).AS("[Order]").WhereColumns("id").ExecuteCommand();
|
||||
var t666 = db.Updateable(dtList).AS("[Order]").WhereColumns("id").ExecuteCommand();
|
||||
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace OrmTest
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -30,22 +30,22 @@ namespace OrmTest
|
||||
}
|
||||
});
|
||||
|
||||
var insertObj = new Order() { Id = 1, Name = "order1" };
|
||||
var insertObj = new Order() { Id = 1, Name = "order1",Price=0 };
|
||||
var updateObjs = new List<Order> {
|
||||
new Order() { Id = 11, Name = "order11" },
|
||||
new Order() { Id = 12, Name = "order12" }
|
||||
new Order() { Id = 11, Name = "order11", Price=0 },
|
||||
new Order() { Id = 12, Name = "order12" , Price=0}
|
||||
};
|
||||
|
||||
//Ignore Price
|
||||
db.Insertable(insertObj).IgnoreColumns(it => new { it.Price }).ExecuteReturnIdentity();//get identity
|
||||
db.Insertable(insertObj).IgnoreColumns("Name", "TestId").ExecuteReturnIdentity();
|
||||
//Ignore CreateTime
|
||||
db.Insertable(insertObj).IgnoreColumns(it => new { it.CreateTime }).ExecuteReturnIdentity();//get identity
|
||||
db.Insertable(insertObj).IgnoreColumns("CreateTime").ExecuteReturnIdentity();
|
||||
|
||||
//Only insert Name and Price
|
||||
db.Insertable(insertObj).InsertColumns(it => new { it.Name, it.Price }).ExecuteReturnIdentity();
|
||||
db.Insertable(insertObj).InsertColumns("Name", "SchoolId").ExecuteReturnIdentity();
|
||||
db.Insertable(insertObj).InsertColumns("Name", "Price").ExecuteReturnIdentity();
|
||||
|
||||
//ignore null columns
|
||||
db.Insertable(insertObj).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();//get change row count
|
||||
db.Insertable(updateObjs).ExecuteCommand();//get change row count
|
||||
|
||||
//Use Lock
|
||||
db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteCommand();
|
||||
|
@ -16,7 +16,7 @@ namespace OrmTest
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -30,16 +30,16 @@ namespace OrmTest
|
||||
}
|
||||
});
|
||||
//by entity
|
||||
db.Deleteable<Order>().Where(new Order() { Id = 1 }).ExecuteCommand();
|
||||
db.Deleteable<Order>().Where(new Order() { Id = 1111 }).ExecuteCommand();
|
||||
|
||||
//by primary key
|
||||
db.Deleteable<Order>().In(1).ExecuteCommand();
|
||||
db.Deleteable<Order>().In(1111).ExecuteCommand();
|
||||
|
||||
//by primary key array
|
||||
db.Deleteable<Order>().In(new int[] { 1, 2 }).ExecuteCommand();
|
||||
db.Deleteable<Order>().In(new int[] { 1111, 2222 }).ExecuteCommand();
|
||||
|
||||
//by expression
|
||||
db.Deleteable<Order>().Where(it => it.Id == 1).ExecuteCommand();
|
||||
db.Deleteable<Order>().Where(it => it.Id == 11111).ExecuteCommand();
|
||||
|
||||
Console.WriteLine("#### Deleteable End ####");
|
||||
|
||||
|
@ -16,20 +16,20 @@ namespace OrmTest
|
||||
Console.WriteLine("#### SqlQueryable Start ####");
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true
|
||||
});
|
||||
|
||||
int total = 0;
|
||||
var list = db.SqlQueryable<Student>("select * from student").ToPageList(1, 2, ref total);
|
||||
var list = db.SqlQueryable<Student>("select * from [order]").ToPageList(1, 2, ref total);
|
||||
|
||||
|
||||
//by expression
|
||||
var list2 = db.SqlQueryable<Student>("select * from student").Where(it => it.Id == 1).ToPageList(1, 2);
|
||||
var list2 = db.SqlQueryable<Student>("select * from [order]").Where(it => it.Id == 1).ToPageList(1, 2);
|
||||
//by sql
|
||||
var list3 = db.SqlQueryable<Student>("select * from student").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
|
||||
var list3 = db.SqlQueryable<Student>("select * from [order]").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
|
||||
|
||||
Console.WriteLine("#### SqlQueryable End ####");
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace OrmTest
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
|
57
Src/Asp.Net/MySqlTest/Demo/Demo7_Ado.cs
Normal file
57
Src/Asp.Net/MySqlTest/Demo/Demo7_Ado.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class Demo7_Ado
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### Ado Start ####");
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
AopEvents = new AopEvents
|
||||
{
|
||||
OnLogExecuting = (sql, p) =>
|
||||
{
|
||||
Console.WriteLine(sql);
|
||||
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||
}
|
||||
}
|
||||
});
|
||||
//sql
|
||||
var dt = db.Ado.GetDataTable("select * from [order] where @id>0 or name=@name", new List<SugarParameter>(){
|
||||
new SugarParameter("@id",1),
|
||||
new SugarParameter("@name","2")
|
||||
});
|
||||
|
||||
//sql
|
||||
var dt2 = db.Ado.GetDataTable("select * from [order] where @id>0 or name=@name", new { id = 1, name = "2" });
|
||||
|
||||
//Stored Procedure
|
||||
//var dt3 = db.Ado.UseStoredProcedure().GetDataTable("sp_school", new { name = "张三", age = 0 });
|
||||
//var nameP = new SugarParameter("@name", "张三");
|
||||
//var ageP = new SugarParameter("@age", null, true);//isOutput=true
|
||||
//var dt4 = db.Ado.UseStoredProcedure().GetDataTable("sp_school", nameP, ageP);
|
||||
|
||||
|
||||
|
||||
//There are many methods to under db.ado
|
||||
var list= db.Ado.SqlQuery<Order>("select * from [order] ");
|
||||
var intValue=db.Ado.SqlQuerySingle<int>("select 1");
|
||||
db.Ado.ExecuteCommand("delete [order] where id>1000");
|
||||
//db.Ado.xxx
|
||||
Console.WriteLine("#### Ado End ####");
|
||||
}
|
||||
}
|
||||
}
|
48
Src/Asp.Net/MySqlTest/Demo/Demo8_Saveable.cs
Normal file
48
Src/Asp.Net/MySqlTest/Demo/Demo8_Saveable.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class Demo8_Saveable
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### Saveable Start ####");
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
AopEvents = new AopEvents
|
||||
{
|
||||
OnLogExecuting = (sql, p) =>
|
||||
{
|
||||
Console.WriteLine(sql);
|
||||
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//insert or update
|
||||
db.Saveable<Order>(new Order() { Id=1, Name="jack" }).ExecuteReturnEntity();
|
||||
|
||||
|
||||
//insert or update
|
||||
db.Saveable<Order>(new Order() { Id = 1000, Name = "jack", CreateTime=DateTime.Now })
|
||||
.InsertColumns(it => new { it.Name,it.CreateTime, it.Price})//if insert into name,CreateTime,Price
|
||||
.UpdateColumns(it => new { it.Name, it.CreateTime })//if update set name CreateTime
|
||||
.ExecuteReturnEntity();
|
||||
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### Saveable End ####");
|
||||
}
|
||||
}
|
||||
}
|
46
Src/Asp.Net/MySqlTest/Demo/Demo9_EntityMain.cs
Normal file
46
Src/Asp.Net/MySqlTest/Demo/Demo9_EntityMain.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class Demo9_EntityMain
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### EntityMain Start ####");
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
AopEvents = new AopEvents
|
||||
{
|
||||
OnLogExecuting = (sql, p) =>
|
||||
{
|
||||
Console.WriteLine(sql);
|
||||
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||
}
|
||||
}
|
||||
});
|
||||
var entityInfo = db.EntityMaintenance.GetEntityInfo<Order>();
|
||||
foreach (var column in entityInfo.Columns)
|
||||
{
|
||||
Console.WriteLine(column.DbColumnName);
|
||||
}
|
||||
|
||||
var dbColumnsName = db.EntityMaintenance.GetDbColumnName<EntityMapper>("Name");
|
||||
|
||||
var dbTableName = db.EntityMaintenance.GetTableName<EntityMapper>();
|
||||
|
||||
//more https://github.com/sunkaixuan/SqlSugar/wiki/9.EntityMain
|
||||
Console.WriteLine("#### EntityMain End ####");
|
||||
}
|
||||
}
|
||||
}
|
42
Src/Asp.Net/MySqlTest/Demo/DemoA_DbMain.cs
Normal file
42
Src/Asp.Net/MySqlTest/Demo/DemoA_DbMain.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class DemoA_DbMain
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### DbMain Start ####");
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
AopEvents = new AopEvents
|
||||
{
|
||||
OnLogExecuting = (sql, p) =>
|
||||
{
|
||||
Console.WriteLine(sql);
|
||||
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var tables = db.DbMaintenance.GetTableInfoList();
|
||||
foreach (var table in tables)
|
||||
{
|
||||
Console.WriteLine(table.Description);
|
||||
}
|
||||
//more https://github.com/sunkaixuan/SqlSugar/wiki/a.DbMain
|
||||
Console.WriteLine("#### DbMain End ####");
|
||||
}
|
||||
}
|
||||
}
|
68
Src/Asp.Net/MySqlTest/Demo/DemoB_Aop.cs
Normal file
68
Src/Asp.Net/MySqlTest/Demo/DemoB_Aop.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class DemoB_Aop
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### Aop Start ####");
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true
|
||||
});
|
||||
db.Aop.OnLogExecuted = (sql, pars) => //SQL executed event
|
||||
{
|
||||
Console.WriteLine("OnLogExecuted"+sql);
|
||||
};
|
||||
db.Aop.OnLogExecuting = (sql, pars) => //SQL executing event (pre-execution)
|
||||
{
|
||||
Console.WriteLine("OnLogExecuting" + sql);
|
||||
};
|
||||
db.Aop.OnError = (exp) =>//SQL execution error event
|
||||
{
|
||||
//exp.sql
|
||||
};
|
||||
db.Aop.OnExecutingChangeSql = (sql, pars) => //SQL executing event (pre-execution,SQL script can be modified)
|
||||
{
|
||||
return new KeyValuePair<string, SugarParameter[]>(sql, pars);
|
||||
};
|
||||
db.Aop.OnDiffLogEvent = it =>//Get data changes
|
||||
{
|
||||
var editBeforeData = it.BeforeData;
|
||||
var editAfterData = it.AfterData;
|
||||
var sql = it.Sql;
|
||||
var parameter = it.Parameters;
|
||||
var businessData = it.BusinessData;
|
||||
var time = it.Time;
|
||||
var diffType = it.DiffType;//enum insert 、update and delete
|
||||
Console.WriteLine(businessData);
|
||||
Console.WriteLine(editBeforeData[0].Columns[1].Value);
|
||||
Console.WriteLine("to");
|
||||
Console.WriteLine(editAfterData[0].Columns[1].Value);
|
||||
//Write logic
|
||||
};
|
||||
|
||||
|
||||
db.Queryable<Order>().ToList();
|
||||
db.Queryable<OrderItem>().ToList();
|
||||
|
||||
//OnDiffLogEvent
|
||||
var data = db.Queryable<Order>().First();
|
||||
data.Name = "changeName";
|
||||
db.Updateable(data).EnableDiffLogEvent("--update Order--").ExecuteCommand();
|
||||
|
||||
Console.WriteLine("#### Aop End ####");
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace OrmTest
|
||||
Console.WriteLine("#### DbFirst Start ####");
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true
|
||||
|
@ -14,12 +14,12 @@ namespace OrmTest
|
||||
Console.WriteLine("#### CodeFirst Start ####");
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
ConnectionString =Config.ConnectionString,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString3,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true
|
||||
});
|
||||
db.DbMaintenance.CreateDatabase();//default bin/database
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
db.CodeFirst.InitTables(typeof(CodeFirstTable1));//Create CodeFirstTable1
|
||||
db.Insertable(new CodeFirstTable1() { Name = "a", Text="a" }).ExecuteCommand();
|
||||
var list = db.Queryable<CodeFirstTable1>().ToList();
|
||||
|
46
Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs
Normal file
46
Src/Asp.Net/MySqlTest/Demo/DemoF_Utilities.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class DemoF_Utilities
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### Utilities Start ####");
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
AopEvents = new AopEvents
|
||||
{
|
||||
OnLogExecuting = (sql, p) =>
|
||||
{
|
||||
Console.WriteLine(sql);
|
||||
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
List<int> ids = Enumerable.Range(1, 100).ToList();
|
||||
db.Utilities.PageEach(ids, 10, list =>
|
||||
{
|
||||
Console.WriteLine(string.Join("," ,list));
|
||||
});
|
||||
|
||||
var list2= db.Utilities.DataTableToList<Order>(db.Ado.GetDataTable("select * from [order]"));
|
||||
|
||||
//more https://github.com/sunkaixuan/SqlSugar/wiki/f.Utilities
|
||||
Console.WriteLine("#### Utilities End ####");
|
||||
}
|
||||
}
|
||||
}
|
36
Src/Asp.Net/MySqlTest/Demo/DemoG_SimpleClient.cs
Normal file
36
Src/Asp.Net/MySqlTest/Demo/DemoG_SimpleClient.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class DemoG_SimpleClient
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("#### SimpleClient Start ####");
|
||||
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
AopEvents = new AopEvents
|
||||
{
|
||||
OnLogExecuting = (sql, p) =>
|
||||
{
|
||||
Console.WriteLine(sql);
|
||||
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Console.WriteLine("#### SimpleClient End ####");
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Text;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class Democ_GobalFilter
|
||||
public class DemoC_GobalFilter
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
@ -38,7 +38,7 @@ namespace OrmTest
|
||||
|
||||
public static SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.MySql, ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true });
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.SqlServer, ConnectionString = Config.ConnectionString, IsAutoCloseConnection = true });
|
||||
|
||||
//single table query gobal filter
|
||||
db.QueryFilter.Add(new SqlFilterItem()
|
||||
|
@ -57,9 +57,16 @@
|
||||
<Compile Include="Demo\Demo4_Deleteable.cs" />
|
||||
<Compile Include="Demo\Demo5_SqlQueryable.cs" />
|
||||
<Compile Include="Demo\Demo6_Queue.cs" />
|
||||
<Compile Include="Demo\Demo7_Ado.cs" />
|
||||
<Compile Include="Demo\Demo8_Saveable.cs" />
|
||||
<Compile Include="Demo\Demo9_EntityMain.cs" />
|
||||
<Compile Include="Demo\DemoA_DbMain.cs" />
|
||||
<Compile Include="Demo\DemoB_Aop.cs" />
|
||||
<Compile Include="Demo\Democ_GobalFilter.cs" />
|
||||
<Compile Include="Demo\DemoD_DbFirst.cs" />
|
||||
<Compile Include="Demo\DemoE_CodeFirst.cs" />
|
||||
<Compile Include="Demo\DemoF_Utilities.cs" />
|
||||
<Compile Include="Demo\DemoG_SimpleClient.cs" />
|
||||
<Compile Include="Models\CarType.cs" />
|
||||
<Compile Include="Models\Custom.cs" />
|
||||
<Compile Include="Models\Mappers.cs" />
|
||||
|
@ -8,20 +8,30 @@ namespace OrmTest
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// OldTestMain.Init();
|
||||
|
||||
//Demo
|
||||
Demo0_SqlSugarClient.Init();
|
||||
Demo1_Queryable.Init();
|
||||
Demo2_Updateable.Init();
|
||||
Democ_GobalFilter.Init();
|
||||
DemoD_DbFirst.Init();
|
||||
DemoE_CodeFirst.Init();
|
||||
Demo3_Insertable.Init();
|
||||
Demo4_Deleteable.Init();
|
||||
Demo5_SqlQueryable.Init();
|
||||
Demo6_Queue.Init();
|
||||
Demo7_Ado.Init();
|
||||
Demo8_Saveable.Init();
|
||||
Demo9_EntityMain.Init();
|
||||
DemoA_DbMain.Init();
|
||||
DemoB_Aop.Init();
|
||||
DemoC_GobalFilter.Init();
|
||||
DemoD_DbFirst.Init(); ;
|
||||
DemoE_CodeFirst.Init();
|
||||
DemoF_Utilities.Init();
|
||||
DemoG_SimpleClient.Init();
|
||||
|
||||
//Unit test
|
||||
NewUnitTest.Init();
|
||||
//NewUnitTest.Init();
|
||||
|
||||
//Rest Data
|
||||
NewUnitTest.RestData();
|
||||
|
||||
Console.WriteLine("all successfully.");
|
||||
Console.ReadKey();
|
||||
|
@ -10,7 +10,7 @@ namespace OrmTest
|
||||
{
|
||||
public static SqlSugarClient Db=> new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -23,6 +23,12 @@ namespace OrmTest
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public static void RestData()
|
||||
{
|
||||
Db.DbMaintenance.TruncateTable<Order>();
|
||||
Db.DbMaintenance.TruncateTable<OrderItem>();
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
CodeFirst();
|
||||
|
@ -48,9 +48,9 @@ namespace OrmTest
|
||||
task8.Wait();
|
||||
UValidate.Check(8, task8.Result[0].id, "ado");
|
||||
|
||||
var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from `order` ;select * from OrderDetail");
|
||||
var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from [order];select * from OrderDetail");
|
||||
|
||||
var task10 = Db.Ado.SqlQueryAsync<Order, OrderItem>("select * from `order`;select * from OrderDetail");
|
||||
var task10 = Db.Ado.SqlQueryAsync<Order, OrderItem>("select * from [order];select * from OrderDetail");
|
||||
task10.Wait();
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,12 @@ namespace OrmTest
|
||||
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" })]
|
||||
[SqlSugar.SugarColumn(DefaultValue="getdate()", IndexGroupNameList =new string[] {"group1" } )]
|
||||
public DateTime? CreateDate { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,24 +11,24 @@ namespace OrmTest
|
||||
|
||||
public static void Json()
|
||||
{
|
||||
Db.CodeFirst.InitTables<JsonTest>();
|
||||
Db.DbMaintenance.TruncateTable<JsonTest>();
|
||||
Db.Insertable(new JsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
|
||||
var list = Db.Queryable<JsonTest>().ToList();
|
||||
Db.CodeFirst.InitTables<UnitJsonTest>();
|
||||
Db.DbMaintenance.TruncateTable<UnitJsonTest>();
|
||||
Db.Insertable(new UnitJsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
|
||||
var list = Db.Queryable<UnitJsonTest>().ToList();
|
||||
UValidate.Check("order1", list.First().Order.Name, "Json");
|
||||
Db.Updateable(new JsonTest() { Id = 1, Order = new Order { Id = 2, Name = "order2" } }).ExecuteCommand();
|
||||
list= Db.Queryable<JsonTest>().ToList();
|
||||
Db.Updateable(new UnitJsonTest() { Id = 1, Order = new Order { Id = 2, Name = "order2" } }).ExecuteCommand();
|
||||
list= Db.Queryable<UnitJsonTest>().ToList();
|
||||
UValidate.Check("order2", list.First().Order.Name, "Json");
|
||||
var list2 = Db.Queryable<JsonTest>().ToList();
|
||||
var list2 = Db.Queryable<UnitJsonTest>().ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class JsonTest
|
||||
public class UnitJsonTest
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "varchar(4000)", IsJson = true)]
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "varchar(max)", IsJson = true)]
|
||||
public Order Order { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -8,19 +9,315 @@ namespace OrmTest
|
||||
{
|
||||
public partial class NewUnitTest
|
||||
{
|
||||
public static void Queryable() {
|
||||
public static void Queryable()
|
||||
{
|
||||
|
||||
var pageindex = 1;
|
||||
var pagesize = 10;
|
||||
var total = 0;
|
||||
var totalPage = 0;
|
||||
var list=Db.Queryable<Order>().ToPageList(pageindex, pagesize, ref total, ref totalPage);
|
||||
var list = Db.Queryable<Order>().ToPageList(pageindex, pagesize, ref total, ref totalPage);
|
||||
|
||||
Db.CodeFirst.InitTables(typeof(CarType));
|
||||
Db.Updateable<CarType>()
|
||||
.SetColumns(it => new CarType { State =SqlSugar.SqlFunc.IIF(it.State==true,false,true) }).Where(it=>true)
|
||||
.ExecuteCommand();
|
||||
//Db.CodeFirst.InitTables(typeof(CarType));
|
||||
//Db.Updateable<CarType>()
|
||||
// .SetColumns(it => new CarType { State = SqlSugar.SqlFunc.IIF(it.State == true, false, true) }).Where(it => true)
|
||||
// .ExecuteCommand();
|
||||
|
||||
//Db.CodeFirst.InitTables(typeof(TestTree));
|
||||
//Db.DbMaintenance.TruncateTable<TestTree>();
|
||||
//Db.Ado.ExecuteCommand("insert testtree values(hierarchyid::GetRoot(),geography :: STGeomFromText ('POINT(55.9271035250276 -3.29431266523898)',4326),'name')");
|
||||
//var list2 = Db.Queryable<TestTree>().ToList();
|
||||
|
||||
Db.CodeFirst.InitTables<UnitGuidTable>();
|
||||
Db.Queryable<UnitGuidTable>().Where(it => it.Id.HasValue).ToList();
|
||||
|
||||
Db.Queryable<Order>().Where(it => SqlSugar.SqlFunc.Equals(it.CreateTime.Date, it.CreateTime.Date)).ToList();
|
||||
|
||||
var sql = Db.Queryable<UnitSelectTest>().Select(it => new UnitSelectTest()
|
||||
{
|
||||
|
||||
DcNull = it.Dc,
|
||||
Dc = it.Int
|
||||
}).ToSql().Key;
|
||||
UValidate.Check(sql, "SELECT [Dc] AS [DcNull] , [Int] AS [Dc] FROM [UnitSelectTest]", "Queryable");
|
||||
|
||||
sql = Db.Updateable<UnitSelectTest2>(new UnitSelectTest2()).ToSql().Key;
|
||||
UValidate.Check(sql, @"UPDATE [UnitSelectTest2] SET
|
||||
[Dc]=@Dc,[IntNull]=@IntNull WHERE [Int]=@Int", "Queryable");
|
||||
|
||||
sql = Db.Queryable<Order>().IgnoreColumns(it => it.CreateTime).ToSql().Key;
|
||||
UValidate.Check(sql, "SELECT [Id],[Name],[Price],[CustomId] FROM [Order] ", "Queryable");
|
||||
sql = Db.Queryable<Order>().IgnoreColumns(it => new { it.Id, it.Name }).ToSql().Key;
|
||||
UValidate.Check(sql, "SELECT [Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable");
|
||||
sql = Db.Queryable<Order>().IgnoreColumns("id").ToSql().Key;
|
||||
UValidate.Check(sql, "SELECT [Name],[Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable");
|
||||
|
||||
var cts = IEnumerbleContains.Data();
|
||||
var list2=Db.Queryable<Order>()
|
||||
.Where(p => /*ids.*/cts.Select(c => c.Id).Contains(p.Id)).ToList();
|
||||
|
||||
var cts2 = IEnumerbleContains.Data().ToList(); ;
|
||||
var list3 = Db.Queryable<Order>()
|
||||
.Where(p => /*ids.*/cts2.Select(c => c.Id).Contains(p.Id)).ToList();
|
||||
|
||||
|
||||
var list4 = Db.Queryable<Order>()
|
||||
.Where(p => new List<int> { 1, 2, 3 }.Where(b => b > 1).Contains(p.Id)).ToList();
|
||||
|
||||
Db.CodeFirst.InitTables<UnitTest3>();
|
||||
var list5 = Db.Queryable<UnitTest3>().Where(it => SqlSugar.SqlFunc.ToString(it.Date.Value.Year) == "1").ToList();
|
||||
var list6 = Db.Queryable<UnitTest3>().Where(it => it.Date.Value.Year == 1).ToList();
|
||||
var list7 = Db.Queryable<UnitTest3>().Where(it => it.Date.Value.Date == DateTime.Now.Date).ToList();
|
||||
|
||||
|
||||
SaleOrder saleOrderInfo = new SaleOrder();
|
||||
Db.CodeFirst.InitTables<SaleOrder>();
|
||||
var result = Db.GetSimpleClient<SaleOrder>().Update(o => new SaleOrder()
|
||||
{
|
||||
OrderStatus = 1,
|
||||
CheckMan = saleOrderInfo.CheckMan,
|
||||
CheckTime = DateTime.Now
|
||||
}, o => o.OrderSn == saleOrderInfo.OrderSn && o.OrderStatus != 1);
|
||||
}
|
||||
|
||||
public static class IEnumerbleContains
|
||||
{
|
||||
public static IEnumerable<Order> Data()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
yield return new Order
|
||||
{
|
||||
Id = i,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
[SugarTable("UnitSaleOrder")]
|
||||
public class SaleOrder
|
||||
{
|
||||
public SaleOrder()
|
||||
{
|
||||
SaleDate = DateTime.Now;
|
||||
Team = 1;
|
||||
AddTime = DateTime.Now;
|
||||
OrderStatus = 0;
|
||||
Points = 0;
|
||||
PayPoints = 0;
|
||||
PointsExchangeMoney = decimal.Zero;
|
||||
IsPushMessage = false;
|
||||
CostAmount = decimal.Zero;
|
||||
OrderAmount = decimal.Zero;
|
||||
RealOrderAmount = decimal.Zero;
|
||||
AccountsDueAmount = decimal.Zero;
|
||||
SettleType = 0;
|
||||
IsPushMessage = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订单号
|
||||
/// </summary>
|
||||
public string OrderSn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户编号
|
||||
/// </summary>
|
||||
public string CustomerNo { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 收货人姓名
|
||||
/// </summary>
|
||||
public string CustomerName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成本总金额
|
||||
/// </summary>
|
||||
public decimal CostAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单总金额
|
||||
/// </summary>
|
||||
public decimal OrderAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 实收金额(整单优惠后)
|
||||
/// </summary>
|
||||
public decimal RealOrderAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 销货日期
|
||||
/// </summary>
|
||||
public DateTime SaleDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下单时间
|
||||
/// </summary>
|
||||
public DateTime AddTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 媒体资源投放ID
|
||||
/// </summary>
|
||||
public string IndustryCode { get; set; }
|
||||
|
||||
public string IndustryName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 班组
|
||||
/// </summary>
|
||||
public int Team { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 销售员编号
|
||||
/// </summary>
|
||||
public string SellerNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 销售员姓名
|
||||
/// </summary>
|
||||
public string SellerName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作人ID
|
||||
/// </summary>
|
||||
public virtual string HandlerCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作者
|
||||
/// </summary>
|
||||
public string Handler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发货仓库代号
|
||||
/// </summary>
|
||||
public string StoreCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发货仓库名称
|
||||
/// </summary>
|
||||
public string StoreName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 销货店铺渠道代号
|
||||
/// </summary>
|
||||
public string ShopChannelCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 销货店铺渠道名称
|
||||
/// </summary>
|
||||
public string ShopChannelName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单产品数
|
||||
/// </summary>
|
||||
public int GoodsNum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 礼品数量
|
||||
/// </summary>
|
||||
public int GiftNum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对应预订单号
|
||||
/// </summary>
|
||||
public string CustomerOrderSn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单赠送积分
|
||||
/// </summary>
|
||||
public int Points { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 应收款金额
|
||||
/// </summary>
|
||||
public decimal AccountsDueAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来自预约单号
|
||||
/// </summary>
|
||||
public string ReserationOrderSn { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 订单状态 0为未审核 1为已审核
|
||||
/// </summary>
|
||||
public int OrderStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 审核人
|
||||
/// </summary>
|
||||
public string CheckMan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 审核时间
|
||||
/// </summary>
|
||||
public DateTime? CheckTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结算类型 0为非金工石(零售) 1为金工石
|
||||
/// </summary>
|
||||
public int SettleType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 使用积分
|
||||
/// </summary>
|
||||
public int PayPoints { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 积分抵现金额
|
||||
/// </summary>
|
||||
public decimal PointsExchangeMoney { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已推送微信消息
|
||||
/// </summary>
|
||||
public bool IsPushMessage { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class SaleOrderBaseInfo
|
||||
{
|
||||
public int GoodsNum { get; set; }
|
||||
|
||||
public int GiftNum { get; set; }
|
||||
|
||||
public decimal OrderAmount { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class UnitTest3
|
||||
{
|
||||
public DateTime? Date { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class UnitSelectTest2
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
public decimal? DcNull { get; set; }
|
||||
public decimal Dc { get; set; }
|
||||
public int? IntNull { get; set; }
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
|
||||
public decimal Int { get; set; }
|
||||
}
|
||||
|
||||
public class UnitSelectTest
|
||||
{
|
||||
public decimal? DcNull { get; set; }
|
||||
public decimal Dc { get; set; }
|
||||
public int? IntNull { get; set; }
|
||||
public decimal Int { get; set; }
|
||||
}
|
||||
|
||||
public class UnitGuidTable
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace OrmTest
|
||||
|
||||
public static SqlSugarClient simpleDb => new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -27,7 +27,7 @@ namespace OrmTest
|
||||
});
|
||||
public static SqlSugarClient ssDb => new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -43,7 +43,7 @@ namespace OrmTest
|
||||
});
|
||||
public static SqlSugarClient singleDb = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
@ -58,7 +58,7 @@ namespace OrmTest
|
||||
});
|
||||
public static SqlSugarClient singleAndSsDb = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.MySql,
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = Config.ConnectionString,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
|
@ -13,10 +13,10 @@ namespace OrmTest
|
||||
public static void Thread3()
|
||||
{
|
||||
Console.WriteLine("Thread3");
|
||||
SimpleAsync3();
|
||||
IsShardSameThreadAsync3();
|
||||
SingleAsync3();
|
||||
SingleAndIsShardSameThreadAsync3();
|
||||
SimpleAsync3().Wait();
|
||||
IsShardSameThreadAsync3().Wait();
|
||||
SingleAsync3().Wait();
|
||||
SingleAndIsShardSameThreadAsync3().Wait();
|
||||
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ namespace OrmTest
|
||||
{
|
||||
public static void Check(object a, object b, object name)
|
||||
{
|
||||
if (a?.ToString() != b?.ToString())
|
||||
if (a?.ToString()?.Trim() != b?.ToString()?.Trim())
|
||||
{
|
||||
throw new Exception(name + " error");
|
||||
}
|
||||
|
@ -11,18 +11,139 @@ namespace OrmTest
|
||||
{
|
||||
public static void Updateable()
|
||||
{
|
||||
Db.CodeFirst.InitTables(typeof(SYS_USER));
|
||||
Db.DbMaintenance.TruncateTable<SYS_USER>();
|
||||
Db.Insertable(new SYS_USER() { USER_ID=1,USER_ACCOUNT = "a", USER_PWD = "b", USER_NAME = "c", PWD_LASTCHTIME = DateTime.Now, PWD_ERRORCOUNT = 1, PWD_LASTERRTIME = DateTime.Now }).ExecuteCommand();
|
||||
Db.Updateable(new SYS_USER() { USER_ID=1, PWD_LASTERRTIME = null }).WhereColumns(it=> new{ it.PWD_ERRORCOUNT, it.PWD_LASTERRTIME }).ExecuteCommand();
|
||||
|
||||
Db.CodeFirst.InitTables(typeof(UnitUser));
|
||||
Db.DbMaintenance.TruncateTable<UnitUser>();
|
||||
Db.Insertable(new UnitUser() { USER_ID=1,USER_ACCOUNT = "a", USER_PWD = "b", USER_NAME = "c", PWD_LASTCHTIME = DateTime.Now, PWD_ERRORCOUNT = 1, PWD_LASTERRTIME = DateTime.Now }).ExecuteCommand();
|
||||
Db.Updateable(new UnitUser() { USER_ID=1, PWD_LASTERRTIME = null }).WhereColumns(it=> new{ it.PWD_ERRORCOUNT, it.PWD_LASTERRTIME }).ExecuteCommand();
|
||||
Db.CodeFirst.InitTables(typeof(UnitBoolTest));
|
||||
var x = new UnitBoolTest();
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => new UnitBoolTest() { BoolValue = !it.BoolValue }).Where(it=>it.Id==1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == !it.BoolValue ).Where(it=>it.Id==1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => new UnitBoolTest() { BoolValue = x.BoolValue }).Where(it => it.Id == 1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => new UnitBoolTest() { BoolValue = !x.BoolValue }).Where(it => it.Id == 1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == !x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue == it.BoolValue).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue == true).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue == !it.BoolValue).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).UpdateColumns(it =>new { it.BoolValue }) .ExecuteCommand();
|
||||
|
||||
|
||||
|
||||
UnitSaveDiary saveDiary = new UnitSaveDiary();
|
||||
saveDiary.ID = 2;
|
||||
saveDiary.TypeID = 10;
|
||||
saveDiary.TypeName = "类型100";
|
||||
saveDiary.Title = "标题1000";
|
||||
saveDiary.Content = "内容";
|
||||
saveDiary.Time = DateTime.Now;
|
||||
saveDiary.IsRemind = false;//无论传false/true 最终执行的结果都是以true执行的
|
||||
|
||||
var sql = Db.Updateable<UnitDiary>().SetColumns(it => new UnitDiary()
|
||||
{
|
||||
IsRemind = saveDiary.IsRemind,
|
||||
}).Where(it => it.ID == saveDiary.ID).ToSql();
|
||||
UValidate.Check(sql.Key, @"UPDATE [Diary] SET
|
||||
[IsRemind] = @Const0 WHERE ( [ID] = @ID1 )", "Updateable");
|
||||
|
||||
|
||||
sql = Db.Updateable<UnitDiary>().SetColumns(it => new UnitDiary()
|
||||
{
|
||||
TypeID = saveDiary.TypeID,
|
||||
}).Where(it => it.ID == saveDiary.ID).ToSql();
|
||||
UValidate.Check(sql.Key, @"UPDATE [Diary] SET
|
||||
[TypeID] = @Const0 WHERE ( [ID] = @ID1 )", "Updateable");
|
||||
|
||||
}
|
||||
}
|
||||
public class UnitSaveDiary
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Content { get; set; }
|
||||
public DateTime? Time { get; set; }
|
||||
public bool IsRemind { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 日记表
|
||||
/// </summary>
|
||||
[SugarTable("Diary")]
|
||||
public class UnitDiary
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int ID { get; set; }
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public int? UserID { get; set; }
|
||||
/// <summary>
|
||||
/// 日记类型ID
|
||||
/// </summary>
|
||||
public int? TypeID { get; set; }
|
||||
/// <summary>
|
||||
/// 日记类型名称
|
||||
/// </summary>
|
||||
public string TypeName { get; set; }
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// 内容
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
/// <summary>
|
||||
/// 时间
|
||||
/// </summary>
|
||||
public DateTime? Time { get; set; }
|
||||
/// <summary>
|
||||
/// 是否提醒
|
||||
/// </summary>
|
||||
public bool? IsRemind { get; set; }
|
||||
/// <summary>
|
||||
/// 封面图
|
||||
/// </summary>
|
||||
public string Cover { get; set; }
|
||||
/// <summary>
|
||||
/// 是否为系统日记 1:系统日记 0:用户日记
|
||||
/// </summary>
|
||||
public bool? IsSystem { get; set; }
|
||||
/// <summary>
|
||||
/// 权重(排序)
|
||||
/// </summary>
|
||||
public int? Sequence { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string IP { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool? IsDelete { get; set; }
|
||||
}
|
||||
|
||||
public class UnitBoolTest
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey =true)]
|
||||
public int Id { get; set; }
|
||||
public bool BoolValue { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 普通用户表
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class SYS_USER
|
||||
public class UnitUser
|
||||
{
|
||||
private System.Int64? _USER_ID;
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user