mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
4.2.1.9
This commit is contained in:
@@ -16,7 +16,8 @@ namespace OrmTest.UnitTest
|
||||
this.Count = eachCount;
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
public void Init()
|
||||
{
|
||||
|
||||
var db = GetInstance();
|
||||
var t1 = db.Queryable<Student>().Where(it => it.Id == 1).ToSql();
|
||||
@@ -35,6 +36,17 @@ namespace OrmTest.UnitTest
|
||||
base.Check(@"SELECT [st].[ID] AS [stid] , [sc].[id] AS [scid] FROM [STudent] st Left JOIN School sc ON ( [st].[SchoolId] = [sc].[id] ) WHERE ( [st].[ID] = @Id0 ) AND ( [sc].[id] = @Id1 ) AND ( [sc].[id] = [st].[ID] )GROUP BY [st].[ID],[sc].[id]ORDER BY [st].[ID] ASC ",
|
||||
null, t2.Key, null, " Mapping t2 error");
|
||||
var x2 = GetInstance();
|
||||
|
||||
var q = x2.Queryable<Student>().AS("t");
|
||||
var t3 = q.ToSql();
|
||||
var t4 = q.ToSql();
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [t] ", null, t3.Key, null, "Mapping t3 error");
|
||||
base.Check("SELECT [ID],[SchoolId],[Name],[CreateTime] FROM [t] ", null, t4.Key, null, "Mapping t3 error");
|
||||
|
||||
var x3 = GetInstance2();
|
||||
x3.MappingTables.Add("Student", "studenT");
|
||||
int count = 0;
|
||||
var t5 = x3.Queryable<Student>().ToPageList(1,2,ref count);
|
||||
}
|
||||
|
||||
public new SqlSugarClient GetInstance()
|
||||
@@ -42,5 +54,16 @@ namespace OrmTest.UnitTest
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
return db;
|
||||
}
|
||||
public SqlSugarClient GetInstance2()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType = InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
|
||||
Console.WriteLine();
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ namespace SqlSugar
|
||||
public IDbBind Bind { get { return this.Db.DbBind; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
public MappingTableList OldMappingTableList { get; set; }
|
||||
public MappingTableList QueryableMappingTableList { get; set; }
|
||||
public bool IsAs { get; set; }
|
||||
public QueryBuilder QueryBuilder
|
||||
{
|
||||
@@ -45,6 +46,7 @@ namespace SqlSugar
|
||||
OldMappingTableList = this.Context.MappingTables;
|
||||
this.Context.MappingTables = this.Context.RewritableMethods.TranslateCopy(this.Context.MappingTables);
|
||||
this.Context.MappingTables.Add(entityName, tableName);
|
||||
this.QueryableMappingTableList = this.Context.MappingTables;
|
||||
return this;
|
||||
}
|
||||
public ISugarQueryable<T> AS(string tableName)
|
||||
@@ -54,6 +56,7 @@ namespace SqlSugar
|
||||
OldMappingTableList = this.Context.MappingTables;
|
||||
this.Context.MappingTables = this.Context.RewritableMethods.TranslateCopy(this.Context.MappingTables);
|
||||
this.Context.MappingTables.Add(entityName, tableName);
|
||||
this.QueryableMappingTableList = this.Context.MappingTables;
|
||||
return this;
|
||||
}
|
||||
public virtual ISugarQueryable<T> With(string withString)
|
||||
@@ -390,7 +393,7 @@ namespace SqlSugar
|
||||
|
||||
public virtual int Count()
|
||||
{
|
||||
|
||||
InitMapping();
|
||||
var sql = string.Empty;
|
||||
if (QueryBuilder.PartitionByValue.IsValuable())
|
||||
{
|
||||
@@ -467,6 +470,7 @@ namespace SqlSugar
|
||||
|
||||
public virtual DataTable ToDataTable()
|
||||
{
|
||||
InitMapping();
|
||||
var sqlObj = this.ToSql();
|
||||
RestoreMapping();
|
||||
var result = this.Db.GetDataTable(sqlObj.Key, sqlObj.Value.ToArray());
|
||||
@@ -499,6 +503,7 @@ namespace SqlSugar
|
||||
|
||||
public virtual List<T> ToList()
|
||||
{
|
||||
InitMapping();
|
||||
return _ToList<T>();
|
||||
}
|
||||
public virtual List<T> ToPageList(int pageIndex, int pageSize)
|
||||
@@ -532,6 +537,7 @@ namespace SqlSugar
|
||||
|
||||
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||
{
|
||||
InitMapping();
|
||||
string sql = QueryBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
return new KeyValuePair<string, List<SugarParameter>>(sql, QueryBuilder.Parameters);
|
||||
@@ -676,6 +682,7 @@ namespace SqlSugar
|
||||
return this.EntityInfo.Columns.Where(it => it.IsIdentity).Select(it => it.DbColumnName).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
protected void RestoreMapping()
|
||||
{
|
||||
if (IsAs && _RestoreMapping)
|
||||
@@ -683,6 +690,11 @@ namespace SqlSugar
|
||||
this.Context.MappingTables = OldMappingTableList == null ? new MappingTableList() : OldMappingTableList;
|
||||
}
|
||||
}
|
||||
protected void InitMapping()
|
||||
{
|
||||
if (this.QueryableMappingTableList != null)
|
||||
this.Context.MappingTables = this.QueryableMappingTableList;
|
||||
}
|
||||
|
||||
private void SetContextModel<TResult>(List<TResult> result, Type entityType)
|
||||
{
|
||||
|
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("4.2.1.8")]
|
||||
[assembly: AssemblyFileVersion("4.2.1.8")]
|
||||
[assembly: AssemblyVersion("4.2.1.9")]
|
||||
[assembly: AssemblyFileVersion("4.2.1.9")]
|
||||
|
Reference in New Issue
Block a user