sunkaixuan
1 year ago
17 changed files with 346 additions and 6 deletions
@ -0,0 +1,31 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
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 = "Driver={OceanBase ODBC 2.0 Driver};Server=172.19.9.9;Port=2883;Database=XIR_TRD;User=XIR_TRD@Xpia2C6G#obtest:1650773680;Password=aaAA11%%;Option=3;"; |
||||
|
/// <summary>
|
||||
|
/// Account have permission to create database
|
||||
|
/// 用有建库权限的数据库账号
|
||||
|
/// </summary>
|
||||
|
public static string ConnectionString2 = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8"; |
||||
|
/// <summary>
|
||||
|
/// Account have permission to create database
|
||||
|
/// 用有建库权限的数据库账号
|
||||
|
/// </summary>
|
||||
|
public static string ConnectionString3 = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8"; |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.ComponentModel.DataAnnotations.Schema; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
[Table("MyAttributeTable")] |
||||
|
//[SugarTable("CustomAttributeTable")]
|
||||
|
public class AttributeTable |
||||
|
{ |
||||
|
|
||||
|
[Key] |
||||
|
//[SugarColumn(IsPrimaryKey =true)]
|
||||
|
public string Id { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
namespace OrmTest |
||||
|
{ |
||||
|
public class CarType |
||||
|
{ |
||||
|
public bool State { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
public class Custom |
||||
|
{ |
||||
|
public int Id { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using SqlSugar; |
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
[SugarTable("MyEntityMapper")] |
||||
|
public class EntityMapper |
||||
|
{ |
||||
|
[SugarColumn(ColumnName ="MyName")] |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,54 @@ |
|||||
|
using SqlSugar; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
[SugarTable("OrderDetail")] |
||||
|
public class OrderItemInfo |
||||
|
{ |
||||
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] |
||||
|
public int ItemId { get; set; } |
||||
|
public int OrderId { get; set; } |
||||
|
public decimal? Price { get; set; } |
||||
|
[SqlSugar.SugarColumn(IsNullable = true)] |
||||
|
public DateTime? CreateTime { get; set; } |
||||
|
[SugarColumn(IsIgnore = true)] |
||||
|
public Order Order { get; set; } |
||||
|
} |
||||
|
[SugarTable("Order")] |
||||
|
public class OrderInfo |
||||
|
{ |
||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] |
||||
|
public int Id { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
[SugarColumn(IsIgnore = true)] |
||||
|
public List<OrderItem> Items { get; set; } |
||||
|
} |
||||
|
public class ABMapping |
||||
|
{ |
||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] |
||||
|
public int AId { get; set; } |
||||
|
public int BId { get; set; } |
||||
|
[SugarColumn(IsIgnore = true)] |
||||
|
public A A { get; set; } |
||||
|
[SugarColumn(IsIgnore = true)] |
||||
|
public B B { get; set; } |
||||
|
|
||||
|
} |
||||
|
public class A |
||||
|
{ |
||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] |
||||
|
public int Id { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
public class B |
||||
|
{ |
||||
|
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)] |
||||
|
public int Id { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.ComponentModel.DataAnnotations.Schema; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
[Table("CustomAttributeTable")] |
||||
|
//[SugarTable("CustomAttributeTable")]
|
||||
|
public class MyCustomAttributeTable |
||||
|
{ |
||||
|
|
||||
|
[Key] |
||||
|
//[SugarColumn(IsPrimaryKey =true)]
|
||||
|
public string Id { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
using SqlSugar; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
[SugarTable("ORDERTEST")] |
||||
|
public class Order |
||||
|
{ |
||||
|
[SugarColumn(IsPrimaryKey = true)] |
||||
|
public decimal Id { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } |
||||
|
public decimal Price { get; set; } |
||||
|
[SugarColumn(IsNullable = true)] |
||||
|
public DateTime CreateTime { get; set; } |
||||
|
[SugarColumn(IsNullable =true)] |
||||
|
public decimal CustomId { get; set; } |
||||
|
|
||||
|
[SugarColumn(IsIgnore = true)] |
||||
|
public string Idname { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
[SqlSugar.SugarTable("OrderDetail")] |
||||
|
public class OrderItem |
||||
|
{ |
||||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true, IsIdentity =true)] |
||||
|
public int ItemId { get; set; } |
||||
|
public int OrderId { get; set; } |
||||
|
public decimal? Price { get; set; } |
||||
|
[SqlSugar.SugarColumn(IsNullable = true)] |
||||
|
public DateTime? CreateTime { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
public class TestTree |
||||
|
{ |
||||
|
[SqlSugar.SugarColumn(ColumnDataType = "hierarchyid")] |
||||
|
public string TreeId { get; set; } |
||||
|
[SqlSugar.SugarColumn(ColumnDataType = "Geography")] |
||||
|
public string GId { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
public class Tree |
||||
|
{ |
||||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true)] |
||||
|
public int Id { get; set; } |
||||
|
public string Name { get; set; } |
||||
|
public int ParentId { get; set; } |
||||
|
[SqlSugar.SugarColumn(IsIgnore = true)] |
||||
|
public Tree Parent { get; set; } |
||||
|
[SqlSugar.SugarColumn(IsIgnore = true)] |
||||
|
public List<Tree> Child { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace OrmTest |
||||
|
{ |
||||
|
public class ViewOrder:Order |
||||
|
{ |
||||
|
public string CustomName { get; set; } |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<OutputType>Exe</OutputType> |
||||
|
<TargetFramework>net6.0</TargetFramework> |
||||
|
<ImplicitUsings>enable</ImplicitUsings> |
||||
|
<Nullable>enable</Nullable> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\SqlSugar.OceanBaseForOracle\SqlSugar.OceanBaseForOracleCore.csproj" /> |
||||
|
<ProjectReference Include="..\SqlSugar.OdbcCore\SqlSugar.OdbcCore.csproj" /> |
||||
|
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<Folder Include="Demo\" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
@ -0,0 +1,54 @@ |
|||||
|
using OrmTest; |
||||
|
using SqlSugar; |
||||
|
using static Npgsql.Replication.PgOutput.Messages.RelationMessage; |
||||
|
|
||||
|
namespace OceanBaseForOracle |
||||
|
{ |
||||
|
internal class Program |
||||
|
{ |
||||
|
static void Main(string[] args) |
||||
|
{ |
||||
|
Console.WriteLine(""); |
||||
|
Console.WriteLine("#### MasterSlave Start ####"); |
||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() |
||||
|
{ |
||||
|
ConnectionString = Config.ConnectionString,//Master Connection
|
||||
|
DbType = DbType.OceanBaseForOracle, |
||||
|
InitKeyType = InitKeyType.Attribute, |
||||
|
IsAutoCloseConnection = true |
||||
|
}); |
||||
|
db.Aop.OnLogExecuted = (s, p) => |
||||
|
{ |
||||
|
Console.WriteLine(db.Ado.Connection.ConnectionString); |
||||
|
}; |
||||
|
Console.WriteLine("Master:"); |
||||
|
db.Insertable(new Order() { Id=109,Name = "abc", CustomId = 1, CreateTime = DateTime.Now }).ExecuteCommand(); |
||||
|
db.Deleteable<Order>().Where(m => m.Id == 109).ExecuteCommand(); |
||||
|
db.Updateable<Order>().SetColumns(m => new Order |
||||
|
{ |
||||
|
Name = "我是修改" |
||||
|
}).Where(m => m.Id == 2).ExecuteCommand(); |
||||
|
Console.WriteLine("Slave:"); |
||||
|
//var s = db.Queryable<Order>().First();
|
||||
|
//var list = db.Queryable<Order>().Select(m => new Order
|
||||
|
//{
|
||||
|
// Id = m.Id,
|
||||
|
// CreateTime = m.CreateTime,
|
||||
|
// CustomId = m.CustomId,
|
||||
|
// Idname = SqlFunc.Subqueryable<Order>().Where(s => s.Id == 2).Select(s => s.Name),
|
||||
|
// Name = m.Name,
|
||||
|
// Price = m.Price,
|
||||
|
//}).ToList();
|
||||
|
//var grouplist = db.Queryable<Order>().OrderByDescending(m=>m.Id).GroupBy(m=>new {m.Id,m.Name}).SelectMergeTable(m => new Order
|
||||
|
//{
|
||||
|
// Id = m.Id,
|
||||
|
// Name = m.Name,
|
||||
|
// CreateTime= SqlFunc.AggregateMin(m.CreateTime),
|
||||
|
// Price= SqlFunc.AggregateSum(m.Price),
|
||||
|
//}).OrderBy(m=>m.Id).Where(m=>m.Id==1).ToList();
|
||||
|
//var orderlist = db.Queryable<Order>().OrderBy(m => new { m.Id, m.Name }).ToList();
|
||||
|
var pageList = db.Queryable<Order>().OrderBy(m=>m.Id).ToOffsetPage(1, 3); |
||||
|
Console.WriteLine("#### MasterSlave End ####"); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue