mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Add user test case
This commit is contained in:
parent
64af343e46
commit
bfd2eb74c3
@ -25,7 +25,10 @@ namespace OrmTest
|
||||
|
||||
db.GetConnection("OrderDb").Insertable(new Order() { Id = 1, CreateTime = DateTime.Now, Name = "a", Price = 10, CustomId = 1 }).ExecuteCommand();
|
||||
db.GetConnection("OrderItemDb").Insertable(new OrderItem() { OrderId = 1, CreateTime = DateTime.Now, Price = 10 }).ExecuteCommand();
|
||||
|
||||
|
||||
db.Queryable<Order>().AsWithAttr()
|
||||
.LeftJoin<OrderItem>((x, y) => x.Id == y.OrderId)
|
||||
.ToList();
|
||||
|
||||
db.Queryable<Order>()
|
||||
.Select(it => new {
|
||||
|
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
using System.Linq;
|
||||
namespace OrmTest
|
||||
{
|
||||
public class CrossDatabase03
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = new SqlSugarClient(new List<ConnectionConfig>()
|
||||
{
|
||||
new ConnectionConfig(){ConfigId="OrderDb",DbType=DbType.SqlServer,ConnectionString="server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST.a",IsAutoCloseConnection=true},
|
||||
new ConnectionConfig(){ConfigId="OrderItemDb",DbType=DbType.SqlServer,ConnectionString="server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST2.a",IsAutoCloseConnection=true }
|
||||
});
|
||||
db.GetConnection("OrderDb").DbMaintenance.CreateDatabase();
|
||||
db.GetConnection("OrderItemDb").DbMaintenance.CreateDatabase();
|
||||
db.Aop.OnLogExecuting = (sql, p) =>Console.WriteLine( UtilMethods.GetNativeSql(sql, p));
|
||||
|
||||
db.GetConnection("OrderDb").CodeFirst.InitTables<Order>();
|
||||
db.GetConnection("OrderItemDb").CodeFirst.InitTables<OrderItem>();
|
||||
|
||||
db.GetConnection("OrderDb").DbMaintenance.TruncateTable<Order>();
|
||||
db.GetConnection("OrderItemDb").DbMaintenance.TruncateTable<OrderItem>();
|
||||
|
||||
db.GetConnection("OrderDb").Insertable(new Order() { Id = 1, CreateTime = DateTime.Now, Name = "a", Price = 10, CustomId = 1 }).ExecuteCommand();
|
||||
db.GetConnection("OrderItemDb").Insertable(new OrderItem() { OrderId = 1, CreateTime = DateTime.Now, Price = 10 }).ExecuteCommand();
|
||||
|
||||
|
||||
db.Queryable<Order>().AsWithAttr()
|
||||
.LeftJoin<OrderItem>((x,y)=>x.Id==y.OrderId)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
[SqlSugar.Tenant("OrderDb")]
|
||||
[SqlSugar.SugarTable("Order8")]
|
||||
public class Order
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int 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 int CustomId { get; set; }
|
||||
[Navigate(NavigateType.OneToMany, nameof(OrderItem.OrderId))]
|
||||
public List<OrderItem> Items { get; set; }
|
||||
}
|
||||
[SqlSugar.SugarTable("OrderDetail8")]
|
||||
[SqlSugar.Tenant("OrderItemDb")]
|
||||
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; }
|
||||
[Navigate(NavigateType.OneToOne, nameof(OrderId))]
|
||||
public Order Order { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
CrossDatabase03.Init();
|
||||
CrossDatabase02.Init();
|
||||
UnitDynamicCoread12321.Init();
|
||||
UnitManyToManyadfafa.Init();
|
||||
|
Loading…
Reference in New Issue
Block a user