Browse Source

Update Demo

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
5c22af3b2e
  1. 50
      Src/Asp.Net/SqlServerTest/Demo/Demo1_SqlSugarClient.cs
  2. 11
      Src/Asp.Net/SqlServerTest/Demo/Demo2_Queryable.cs
  3. 20
      Src/Asp.Net/SqlServerTest/Models/Class1.cs
  4. 2
      Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
  5. BIN
      Src/Asp.Net/SqlSugar/4.9.9.11 net 版本DLL .rar

50
Src/Asp.Net/SqlServerTest/Demo/Demo1_SqlSugarClient.cs

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -13,8 +15,50 @@ namespace OrmTest
{
SingletonPattern();//单例
DistributedTransactionExample();//分布式事务
CustomAttribute();//自定义特性
}
private static void CustomAttribute()
{
Console.WriteLine("");
Console.WriteLine("#### Custom Attribute Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute,
ConfigureExternalServices = new ConfigureExternalServices()
{
EntityService = (property, column) =>
{
var attributes = property.GetCustomAttributes(true);//get all attributes
if (attributes.Any(it => it is KeyAttribute))// by attribute set primarykey
{
column.IsPrimarykey = true;
}
},
EntityNameService = (type, entity) =>
{
var attributes = type.GetCustomAttributes(true);
if (attributes.Any(it => it is TableAttribute))
{
entity.DbTableName = (attributes.First(it => it is TableAttribute) as TableAttribute).Name;
}
}
}
});
db.CodeFirst.InitTables<MyCustomAttributeTable>();//Create Table
db.Insertable(new MyCustomAttributeTable() { Id = Guid.NewGuid().ToString(), Name = "Name" }).ExecuteCommand();
var list = db.Queryable<MyCustomAttributeTable>().ToList();
Console.WriteLine("#### Custom Attribute End ####");
}
private static void SingletonPattern()
{
Console.WriteLine("");
@ -65,6 +109,12 @@ namespace OrmTest
new ConnectionConfig(){ ConfigId=2, DbType=DbType.MySql, ConnectionString=Config.ConnectionString4 ,InitKeyType=InitKeyType.Attribute ,IsAutoCloseConnection=true}
});
db.MappingTables.Add(typeof(Order).Name, typeof(Order).Name + "2018");
db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order));
db.MappingTables.Add(typeof(Order).Name, typeof(Order).Name + "2019");
db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order));//
//use first(SqlServer)
db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Order), typeof(OrderItem));//
db.Insertable(new Order() { Name = "order1", CreateTime = DateTime.Now }).ExecuteCommand();

11
Src/Asp.Net/SqlServerTest/Demo/Demo2_Queryable.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
class Demo2_Queryable
{
}
}

20
Src/Asp.Net/SqlServerTest/Models/Class1.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
namespace OrmTest
{
[Table(Name = "CustomAttributeTable")]
//[SugarTable("CustomAttributeTable")]
public class MyCustomAttributeTable
{
[Key]
//[SugarColumn(IsPrimaryKey =true)]
public string Id { get; set; }
public string Name { get; set; }
}
}

2
Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

@ -49,6 +49,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Demo\Demo2_Queryable.cs" />
<Compile Include="Models\Class1.cs" />
<Compile Include="Models\Order.cs" />
<Compile Include="Models\OrderItem.cs" />
<Compile Include="Demo\Demo1_SqlSugarClient.cs" />

BIN
Src/Asp.Net/SqlSugar/4.9.9.11 net 版本DLL .rar

Binary file not shown.
Loading…
Cancel
Save