mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Multi database query page bug
This commit is contained in:
parent
87e7bce7af
commit
b7eda4c803
@ -77,6 +77,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\Test01.cs" />
|
||||
<Compile Include="UnitTest\UInsert.cs" />
|
||||
<Compile Include="UnitTest\UQueryable2.cs" />
|
||||
<Compile Include="UnitTest\UQueue.cs" />
|
||||
|
100
Src/Asp.Net/SqlServerTest/UnitTest/Test01.cs
Normal file
100
Src/Asp.Net/SqlServerTest/UnitTest/Test01.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public partial class NewUnitTest
|
||||
{
|
||||
[SugarTable("UnitUser")]
|
||||
public class User2
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int Id { set; get; }
|
||||
public string Name { set; get; }
|
||||
public int DepartmentId { set; get; }
|
||||
}
|
||||
[SugarTable("UnitOrder")]
|
||||
public class Order2
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int Id { set; get; }
|
||||
public string Name { set; get; }
|
||||
public int UserId { set; get; }
|
||||
}
|
||||
[SugarTable("UnitDepartment")]
|
||||
public class Department2
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int Id { set; get; }
|
||||
public string Name { set; get; }
|
||||
}
|
||||
public static async Task QueryableAsync2()
|
||||
{
|
||||
DataBaseInitialize();
|
||||
var context = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = "Data Source=.;Initial Catalog=test2222;User id=sa;Password=haosql;pooling=true;min pool size = 2;max pool size=100;",
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
});
|
||||
//调式代码 用来打印SQL
|
||||
context.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "开始\r\n" + sql + "\r\n" + context.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
};
|
||||
context.Aop.OnLogExecuted = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "结束\r\n" + sql + "\r\n" + context.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
};
|
||||
var recordCount = new RefAsync<int>();
|
||||
//var result = await context.Queryable<Order, User, Department>((o, u, d) => new JoinQueryInfos
|
||||
var result = await context.Queryable<Order2, User2>((o, u) => new JoinQueryInfos
|
||||
(
|
||||
JoinType.Left, o.UserId == u.Id
|
||||
//,JoinType.Left, u.DepartmentId == d.Id
|
||||
))
|
||||
.AS<Order2>("dbo.UnitOrder")
|
||||
.AS<User2>("test1111.dbo.UnitUser")
|
||||
//.AS<Department>("test1.dbo.Department")
|
||||
.Select(o => new User2() { Id = o.Id, Name = o.Name })
|
||||
.ToPageListAsync(1, 10, recordCount);
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
public static void DataBaseInitialize()
|
||||
{
|
||||
//数据库1
|
||||
var context1 = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = "Data Source=.;Initial Catalog=test1111;User id=sa;Password=haosql;pooling=true;min pool size = 2;max pool size=100;",
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
});
|
||||
context1.DbMaintenance.CreateDatabase();
|
||||
context1.CodeFirst.InitTables(typeof(User2));
|
||||
context1.CodeFirst.InitTables(typeof(Department2));
|
||||
if (context1.Queryable<User2>().Where(t => t.Id == 1).Count() == 0)
|
||||
context1.Insertable(new User2() { Id = 1, Name = "TestUser", DepartmentId = 1 }).ExecuteCommand();
|
||||
if (context1.Queryable<Department2>().Where(t => t.Id == 1).Count() == 0)
|
||||
context1.Insertable(new Department2() { Id = 1, Name = "TestDepartment" }).ExecuteCommand();
|
||||
//数据库2
|
||||
var context2 = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = "Data Source=.;Initial Catalog=test2222;User id=sa;Password=haosql;pooling=true;min pool size = 2;max pool size=100;",
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
});
|
||||
context2.DbMaintenance.CreateDatabase();
|
||||
context2.CodeFirst.InitTables(typeof(Order2));
|
||||
if (context1.Queryable<User2>().Where(t => t.Id == 1).Count() == 0)
|
||||
context2.Insertable(new Order2() { Id = 1, Name = "Order", UserId = 1 }).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
@ -1083,7 +1083,9 @@ namespace SqlSugar
|
||||
}
|
||||
public async Task<List<T>> ToPageListAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
var oldMapping = this.Context.MappingTables;
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
this.Context.MappingTables = oldMapping;
|
||||
return await this.Clone().ToPageListAsync(pageIndex, pageSize);
|
||||
}
|
||||
public async Task<string> ToJsonAsync()
|
||||
@ -1108,7 +1110,9 @@ namespace SqlSugar
|
||||
}
|
||||
public async Task<string> ToJsonPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
var oldMapping = this.Context.MappingTables;
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
this.Context.MappingTables = oldMapping;
|
||||
return await this.Clone().ToJsonPageAsync(pageIndex, pageSize);
|
||||
}
|
||||
public async Task<DataTable> ToDataTableAsync()
|
||||
@ -1135,7 +1139,9 @@ namespace SqlSugar
|
||||
}
|
||||
public async Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
var oldMapping = this.Context.MappingTables;
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
this.Context.MappingTables = oldMapping;
|
||||
return await this.Clone().ToDataTablePageAsync(pageIndex, pageSize);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user