Update demo

This commit is contained in:
sunkaixuna 2021-07-31 21:14:48 +08:00
parent 77d5c19cb6
commit 53722e0000
5 changed files with 77 additions and 10 deletions

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PgSqlTest.Demo
{
class DemoH_Snowflake
{
}
}

View File

@ -0,0 +1,49 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class DemoL_Snowflake
{
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)));
}
}
});
db.CodeFirst.InitTables<SnowflakeModel>();
Console.WriteLine(db.Queryable<SnowflakeModel>().Count());
var id= db.Insertable(new SnowflakeModel()
{
Name="哈哈"
}).ExecuteReturnSnowflakeId();
var ids = db.Insertable(db.Queryable<SnowflakeModel>().Take(10).ToList()).ExecuteReturnSnowflakeIdList();
Console.WriteLine(db.Queryable<SnowflakeModel>().Count());
}
}
public class SnowflakeModel
{
[SugarColumn(IsPrimaryKey =true)]
public long Id { get; set; }
public string Name{get;set; }
}
}

View File

@ -32,6 +32,7 @@ namespace OrmTest
DemoG_SimpleClient.Init();
DemoH_Tenant.Init();
DemoJ_Report.Init();
DemoL_Snowflake.Init();
//Unit test
//NewUnitTest.Init();

View File

@ -69,6 +69,7 @@
<Compile Include="Demo\DemoG_SimpleClient.cs" />
<Compile Include="Demo\DemoH_Tenant.cs" />
<Compile Include="Demo\DemoJ_Report.cs" />
<Compile Include="Demo\DemoL_Snowflake.cs" />
<Compile Include="Models\DataDictionary.cs" />
<Compile Include="Models\Custom.cs" />
<Compile Include="Models\EntityMapper.cs" />

View File

@ -91,9 +91,10 @@ namespace SqlSugar
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var snowProperty=entity.Columns.FirstOrDefault(it => it.IsPrimarykey && it.PropertyInfo.PropertyType == UtilConstants.LongType);
Check.Exception(snowProperty==null, "The entity sets the primary key and is long");
foreach (var item in this.InsertObjs)
Check.Exception(snowProperty.IsIdentity == true, "SnowflakeId IsIdentity can't true");
foreach (var item in this.InsertBuilder.DbColumnInfoList.Where(it=>it.PropertyName==snowProperty.PropertyName))
{
snowProperty.PropertyInfo.SetValue(item,id);
item.Value = id;
}
this.ExecuteCommand();
return id;
@ -104,10 +105,11 @@ namespace SqlSugar
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var snowProperty = entity.Columns.FirstOrDefault(it => it.IsPrimarykey && it.PropertyInfo.PropertyType == UtilConstants.LongType);
Check.Exception(snowProperty == null, "The entity sets the primary key and is long");
foreach (var item in InsertObjs)
Check.Exception(snowProperty.IsIdentity == true, "SnowflakeId IsIdentity can't true");
foreach (var item in this.InsertBuilder.DbColumnInfoList.Where(it => it.PropertyName == snowProperty.PropertyName))
{
var id = SnowFlakeSingle.instance.getID();;
snowProperty.PropertyInfo.SetValue(item, id);
var id = SnowFlakeSingle.instance.getID();
item.Value = id;
result.Add(id);
}
this.ExecuteCommand();
@ -119,9 +121,10 @@ namespace SqlSugar
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var snowProperty = entity.Columns.FirstOrDefault(it => it.IsPrimarykey && it.PropertyInfo.PropertyType == UtilConstants.LongType);
Check.Exception(snowProperty == null, "The entity sets the primary key and is long");
foreach (var item in this.InsertObjs)
Check.Exception(snowProperty.IsIdentity == true, "SnowflakeId IsIdentity can't true");
foreach (var item in this.InsertBuilder.DbColumnInfoList.Where(it => it.PropertyName == snowProperty.PropertyName))
{
snowProperty.PropertyInfo.SetValue(item, id);
item.Value = id;
}
await this.ExecuteCommandAsync();
return id;
@ -132,10 +135,11 @@ namespace SqlSugar
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
var snowProperty = entity.Columns.FirstOrDefault(it => it.IsPrimarykey && it.PropertyInfo.PropertyType == UtilConstants.LongType);
Check.Exception(snowProperty == null, "The entity sets the primary key and is long");
foreach (var item in InsertObjs)
Check.Exception(snowProperty.IsIdentity == true, "SnowflakeId IsIdentity can't true");
foreach (var item in this.InsertBuilder.DbColumnInfoList.Where(it => it.PropertyName == snowProperty.PropertyName))
{
var id = SnowFlakeSingle.instance.getID(); ;
snowProperty.PropertyInfo.SetValue(item, id);
var id = SnowFlakeSingle.instance.getID();
item.Value = id;
result.Add(id);
}
await this.ExecuteCommandAsync();