mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-26 14:15:50 +08:00
Update Core
This commit is contained in:
@@ -32,7 +32,7 @@ namespace OrmTest.UnitTest
|
||||
.GroupBy(st => st.Id)
|
||||
.GroupBy((st,sc) => sc.Id).OrderBy(st => st.Id,OrderByType.Asc)
|
||||
.Select((st,sc)=> new { stid=st.Id,scid=sc.Id}).ToSql();
|
||||
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 ",
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OrmTest.UnitTest
|
||||
var t1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Inner,st.Id==sc.Id
|
||||
}).GroupBy(st => st.Id).Having(st => SqlFunc.AggregateAvg(st.Id) == 1).Select(st => new { avgId = SqlFunc.AggregateAvg(st.Id) }).ToSql();
|
||||
base.Check("SELECT AVG(`st`.`ID`) AS `avgId` FROM `STudent` st Inner JOIN School sc ON ( `st`.`ID` = `sc`.`Id` ) GROUP BY `st`.`ID` HAVING (AVG(`st`.`ID`) = @Const0 ) ",
|
||||
base.Check("SELECT AVG(`st`.`ID`) AS `avgId` FROM `STudent` st Inner JOIN School sc ON ( `st`.`ID` = `sc`.`Id` ) GROUP BY `st`.`ID` HAVING (AVG(`st`.`ID`) = @Const0 ) ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0",1)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OrmTest.UnitTest
|
||||
.GroupBy(st => st.Id)
|
||||
.GroupBy((st,sc) => sc.Id).OrderBy(st => st.Id,OrderByType.Asc)
|
||||
.Select((st,sc)=> new { stid=st.Id,scid=sc.Id}).ToSql();
|
||||
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 ",
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OrmTest.UnitTest
|
||||
var t1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Inner,st.Id==sc.Id
|
||||
}).GroupBy(st => st.Id).Having(st => SqlFunc.AggregateAvg(st.Id) == 1).Select(st => new { avgId = SqlFunc.AggregateAvg(st.Id) }).ToSql();
|
||||
base.Check("SELECT AVG([st].[ID]) AS [avgId] FROM [STudent] st Inner JOIN School sc ON ( [st].[ID] = [sc].[Id] ) GROUP BY [st].[ID] HAVING (AVG([st].[ID]) = @Const0 ) ",
|
||||
base.Check("SELECT AVG([st].[ID]) AS [avgId] FROM [STudent] st Inner JOIN School sc ON ( [st].[ID] = [sc].[Id] ) GROUP BY [st].[ID] HAVING (AVG([st].[ID]) = @Const0 ) ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0",1)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual void InitTables(Type entityType)
|
||||
{
|
||||
|
||||
this.Context.RewritableMethods.RemoveCacheAll();
|
||||
this.Context.InitMppingInfo(entityType);
|
||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||
{
|
||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||
|
||||
@@ -236,7 +236,7 @@ namespace SqlSugar
|
||||
method = getString;
|
||||
if (bindProperyTypeName == "guid")
|
||||
{
|
||||
method = getConvertStringGuid;
|
||||
method =isNullableType? getConvertStringGuid : getStringGuid;
|
||||
}
|
||||
break;
|
||||
case CSharpDataType.DateTime:
|
||||
@@ -261,7 +261,8 @@ namespace SqlSugar
|
||||
method = isNullableType ? getConvertStringGuid : getStringGuid;
|
||||
break;
|
||||
case CSharpDataType.@byte:
|
||||
method = isNullableType ? getConvertByte : getByte;
|
||||
if (bindProperyTypeName == "byte")
|
||||
method = isNullableType ? getConvertByte : getByte;
|
||||
break;
|
||||
case CSharpDataType.@enum:
|
||||
method = isNullableType ? getConvertEnum_Null.MakeGenericMethod(bindPropertyType) : getEnum.MakeGenericMethod(bindPropertyType);
|
||||
|
||||
@@ -8,6 +8,8 @@ using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Reflection;
|
||||
using System.Dynamic;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
#region T1
|
||||
@@ -88,12 +90,14 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual ISugarQueryable<T> AddParameters(SugarParameter[] parameters)
|
||||
{
|
||||
QueryBuilder.Parameters.AddRange(parameters);
|
||||
if (parameters != null)
|
||||
QueryBuilder.Parameters.AddRange(parameters);
|
||||
return this;
|
||||
}
|
||||
public virtual ISugarQueryable<T> AddParameters(SugarParameter parameter)
|
||||
{
|
||||
QueryBuilder.Parameters.Add(parameter);
|
||||
if (parameter != null)
|
||||
QueryBuilder.Parameters.Add(parameter);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -646,6 +650,10 @@ namespace SqlSugar
|
||||
var entityType = typeof(TResult);
|
||||
using (var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray()))
|
||||
{
|
||||
if (typeof(TResult) == typeof(ExpandoObject))
|
||||
{
|
||||
return this.Context.RewritableMethods.DataReaderToExpandoObjectList(dataReader) as List<TResult>;
|
||||
}
|
||||
if (entityType.IsAnonymousType() || isComplexModel)
|
||||
{
|
||||
result = this.Context.RewritableMethods.DataReaderToDynamicList<TResult>(dataReader);
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace SqlSugar
|
||||
{
|
||||
batchInsetrSql.Append(SqlTemplateBatchUnion);
|
||||
}
|
||||
batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), it.DbColumnName))));
|
||||
batchInsetrSql.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value),Builder.GetTranslationColumnName(it.DbColumnName)))));
|
||||
++i;
|
||||
}
|
||||
pageIndex++;
|
||||
|
||||
@@ -448,6 +448,11 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.GroupByValue == null) return null;
|
||||
if (this.GroupByValue.Last() != ' ' )
|
||||
{
|
||||
return this.GroupByValue + PubConst.Space;
|
||||
}
|
||||
return this.GroupByValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace SqlSugar
|
||||
{
|
||||
updateTable.Append(SqlTemplateBatchUnion);
|
||||
}
|
||||
updateTable.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), it.DbColumnName))));
|
||||
updateTable.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value),Builder.GetTranslationColumnName(it.DbColumnName)))));
|
||||
++i;
|
||||
}
|
||||
pageIndex++;
|
||||
|
||||
@@ -36,6 +36,24 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///DataReader to Dynamic List
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
/// <returns></returns>
|
||||
public List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader)
|
||||
{
|
||||
List<ExpandoObject> result = new List<ExpandoObject>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(DataReaderToExpandoObject(reader));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///DataReader to DataReaderToDictionary
|
||||
/// </summary>
|
||||
@@ -145,7 +163,7 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Serialize
|
||||
@@ -189,7 +207,7 @@ namespace SqlSugar
|
||||
var jsonString = SerializeObject(sourceObject);
|
||||
return DeserializeObject<T>(jsonString);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DataTable
|
||||
@@ -208,7 +226,7 @@ namespace SqlSugar
|
||||
}
|
||||
return JsonConvert.DeserializeObject<dynamic>(JsonConvert.SerializeObject(deserializeObject));
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Cache
|
||||
@@ -230,9 +248,9 @@ namespace SqlSugar
|
||||
public void RemoveCache<T>(string key)
|
||||
{
|
||||
CacheManager<T>.GetInstance().Remove(key);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SugarDynamic
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -154,15 +154,6 @@ namespace SqlSugar
|
||||
get; set;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 如果类库是.NET 4.5请删除该属性
|
||||
///// If the SqlSugar library is.NET 4.5, delete the property
|
||||
///// </summary>
|
||||
//public override DataRowVersion SourceVersion
|
||||
//{
|
||||
// get; set;
|
||||
//}
|
||||
|
||||
public override void ResetDbType()
|
||||
{
|
||||
this.DbType = System.Data.DbType.String;
|
||||
|
||||
@@ -17,7 +17,26 @@ namespace SqlSugar
|
||||
var isValue = expression.Member.Name == "Value" && expression.Member.DeclaringType.Name == "Nullable`1";
|
||||
var isBool = expression.Type == PubConst.BoolType;
|
||||
var isValueBool = isValue && isBool && parameter.BaseExpression == null;
|
||||
if (isValueBool)
|
||||
var isLength = expression.Member.Name == "Length" && (expression.Expression as MemberExpression).Type == PubConst.StringType;
|
||||
if (isLength)
|
||||
{
|
||||
var oldCommonTempDate = parameter.CommonTempData;
|
||||
parameter.CommonTempData = CommonTempDataType.Result;
|
||||
this.Expression = expression.Expression;
|
||||
var isConst=this.Expression is ConstantExpression;
|
||||
this.Start();
|
||||
var methodParamter = new MethodCallExpressionArgs() { IsMember = !isConst, MemberName = parameter.CommonTempData, MemberValue = null };
|
||||
var result = this.Context.DbMehtods.Length(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>() {
|
||||
methodParamter
|
||||
}
|
||||
});
|
||||
base.AppendMember(parameter, isLeft, result);
|
||||
parameter.CommonTempData = oldCommonTempDate;
|
||||
return;
|
||||
}
|
||||
else if (isValueBool)
|
||||
{
|
||||
isValue = false;
|
||||
}
|
||||
@@ -69,14 +88,14 @@ namespace SqlSugar
|
||||
var isSingle = parameter.Context.ResolveType == ResolveExpressType.WhereSingle;
|
||||
if (isSetTempData)
|
||||
{
|
||||
fieldName = GetName(parameter, expression, null,isSingle);
|
||||
fieldName = GetName(parameter, expression, null, isSingle);
|
||||
baseParameter.CommonTempData = fieldName;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isValueBool)
|
||||
{
|
||||
fieldName = GetName(parameter, expression.Expression as MemberExpression, isLeft,isSingle);
|
||||
fieldName = GetName(parameter, expression.Expression as MemberExpression, isLeft, isSingle);
|
||||
}
|
||||
else if (ExpressionTool.IsConstExpression(expression))
|
||||
{
|
||||
@@ -86,7 +105,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
fieldName = GetName(parameter, expression, isLeft,isSingle);
|
||||
fieldName = GetName(parameter, expression, isLeft, isSingle);
|
||||
}
|
||||
if (expression.Type == PubConst.BoolType && baseParameter.OperatorValue.IsNullOrEmpty())
|
||||
{
|
||||
@@ -105,7 +124,7 @@ namespace SqlSugar
|
||||
break;
|
||||
case ResolveExpressType.ArrayMultiple:
|
||||
case ResolveExpressType.ArraySingle:
|
||||
fieldName = GetName(parameter, expression, isLeft,parameter.Context.ResolveType== ResolveExpressType.ArraySingle);
|
||||
fieldName = GetName(parameter, expression, isLeft, parameter.Context.ResolveType == ResolveExpressType.ArraySingle);
|
||||
base.Context.Result.Append(fieldName);
|
||||
break;
|
||||
default:
|
||||
@@ -147,7 +166,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetMultipleName(parameter,expression,IsLeft);
|
||||
return GetMultipleName(parameter, expression, IsLeft);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace SqlSugar
|
||||
public interface IRewritableMethods
|
||||
{
|
||||
ExpandoObject DataReaderToExpandoObject(IDataReader reader);
|
||||
List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader);
|
||||
List<T> DataReaderToDynamicList<T>(IDataReader reader);
|
||||
string SerializeObject(object value);
|
||||
T DeserializeObject<T>(string value);
|
||||
|
||||
@@ -5,10 +5,12 @@ using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SqlSugar4 Core")]
|
||||
[assembly: AssemblyDescription("author sunkaixuan Apache Licence 2.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SqlSugar")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyProduct("SqlSugar 4")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
@@ -17,5 +19,5 @@ using System.Runtime.InteropServices;
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1c022a5c-4e4d-4026-a8a3-f659b9740a1a")]
|
||||
[assembly: AssemblyVersion("4.2.1.8")]
|
||||
[assembly: AssemblyFileVersion("4.2.1.8")]
|
||||
[assembly: AssemblyVersion("4.2.2.3")]
|
||||
[assembly: AssemblyFileVersion("4.2.2.3")]
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace SqlSugar
|
||||
|
||||
public override void BeginTran(string transactionName)
|
||||
{
|
||||
((MySqlConnection)this.Connection).BeginTransaction();
|
||||
base.BeginTran();
|
||||
}
|
||||
/// <summary>
|
||||
/// Only SqlServer
|
||||
@@ -43,7 +43,7 @@ namespace SqlSugar
|
||||
/// <param name="transactionName"></param>
|
||||
public override void BeginTran(IsolationLevel iso, string transactionName)
|
||||
{
|
||||
((MySqlConnection)this.Connection).BeginTransaction(iso);
|
||||
base.BeginTran(iso);
|
||||
}
|
||||
public override IDataAdapter GetAdapter()
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace SqlSugar
|
||||
{
|
||||
updateTable.Append(SqlTemplateBatchUnion);
|
||||
}
|
||||
updateTable.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value), it.DbColumnName))));
|
||||
updateTable.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value),this.Builder.GetTranslationColumnName(it.DbColumnName)))));
|
||||
++i;
|
||||
}
|
||||
pageIndex++;
|
||||
|
||||
@@ -31,7 +31,8 @@ namespace SqlSugar
|
||||
/// <param name="transactionName"></param>
|
||||
public override void BeginTran(string transactionName)
|
||||
{
|
||||
((SqlConnection)this.Connection).BeginTransaction(transactionName);
|
||||
CheckConnection();
|
||||
base.Transaction = ((SqlConnection)this.Connection).BeginTransaction(transactionName);
|
||||
}
|
||||
/// <summary>
|
||||
/// Only SqlServer
|
||||
@@ -40,7 +41,8 @@ namespace SqlSugar
|
||||
/// <param name="transactionName"></param>
|
||||
public override void BeginTran(IsolationLevel iso, string transactionName)
|
||||
{
|
||||
((SqlConnection)this.Connection).BeginTransaction(iso, transactionName);
|
||||
CheckConnection();
|
||||
base.Transaction = ((SqlConnection)this.Connection).BeginTransaction(iso, transactionName);
|
||||
}
|
||||
public override IDataAdapter GetAdapter()
|
||||
{
|
||||
@@ -89,7 +91,8 @@ namespace SqlSugar
|
||||
sqlParameter.DbType = parameter.DbType;
|
||||
sqlParameter.Direction = parameter.Direction;
|
||||
result[index] = sqlParameter;
|
||||
if (sqlParameter.Direction == ParameterDirection.Output) {
|
||||
if (sqlParameter.Direction == ParameterDirection.Output)
|
||||
{
|
||||
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
|
||||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
|
||||
this.OutputParameters.Add(sqlParameter);
|
||||
|
||||
@@ -34,8 +34,12 @@ namespace SqlSugar
|
||||
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
|
||||
new KeyValuePair<string, CSharpDataType>("int32",CSharpDataType.@int),
|
||||
new KeyValuePair<string, CSharpDataType>("integer32",CSharpDataType.@int),
|
||||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@int),
|
||||
|
||||
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("varchar2",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("nvarchar",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("nvarchar2",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
|
||||
new KeyValuePair<string, CSharpDataType>("num",CSharpDataType.@string),
|
||||
|
||||
@@ -68,7 +68,11 @@ namespace SqlSugar
|
||||
}
|
||||
protected void InitMppingInfo<T>()
|
||||
{
|
||||
string cacheKey = "Context.InitAttributeMappingTables" + typeof(T).FullName;
|
||||
InitMppingInfo(typeof(T));
|
||||
}
|
||||
public void InitMppingInfo(Type type)
|
||||
{
|
||||
string cacheKey = "Context.InitAttributeMappingTables" + type.FullName;
|
||||
var entityInfo = this.Context.RewritableMethods.GetCacheInstance<EntityInfo>().Func(cacheKey,
|
||||
(cm, key) =>
|
||||
{
|
||||
@@ -77,7 +81,7 @@ namespace SqlSugar
|
||||
},
|
||||
(cm, key) =>
|
||||
{
|
||||
var reval = this.Context.EntityProvider.GetEntityInfo<T>();
|
||||
var reval = this.Context.EntityProvider.GetEntityInfo(type);
|
||||
return reval;
|
||||
});
|
||||
InitMppingInfo(entityInfo);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
@@ -98,9 +99,9 @@ namespace SqlSugar
|
||||
/// <summary>
|
||||
/// Lambda Query operation
|
||||
/// </summary>
|
||||
public virtual ISugarQueryable<SugarDynamic> Queryable(string tableName, string shortName)
|
||||
public virtual ISugarQueryable<ExpandoObject> Queryable(string tableName, string shortName)
|
||||
{
|
||||
var queryable = Queryable<SugarDynamic>();
|
||||
var queryable = Queryable<ExpandoObject>();
|
||||
queryable.SqlBuilder.QueryBuilder.EntityName = tableName;
|
||||
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
|
||||
return queryable;
|
||||
@@ -263,6 +264,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null");
|
||||
var insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
|
||||
var columns = columnDictionary.Select(it => it.Key).ToList();
|
||||
@@ -270,6 +272,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
if (insertDynamicObject is T)
|
||||
{
|
||||
return this.Insertable((T)insertDynamicObject);
|
||||
@@ -293,26 +296,32 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(Expression<Func<T, bool>> expression) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(expression);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(dynamic primaryKeyValue) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(primaryKeyValue);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(dynamic[] primaryKeyValues) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(primaryKeyValues);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(List<dynamic> pkValue) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().In(pkValue);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(T deleteObj) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(deleteObj);
|
||||
}
|
||||
public virtual IDeleteable<T> Deleteable<T>(List<T> deleteObjs) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
return this.Deleteable<T>().Where(deleteObjs);
|
||||
}
|
||||
#endregion
|
||||
@@ -339,6 +348,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>(Dictionary<string, object> columnDictionary) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Updateable.columnDictionary can't be null");
|
||||
var updateObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
|
||||
var columns = columnDictionary.Select(it => it.Key).ToList();
|
||||
@@ -346,6 +356,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual IUpdateable<T> Updateable<T>(dynamic updateDynamicObject) where T : class, new()
|
||||
{
|
||||
InitMppingInfo<T>();
|
||||
if (updateDynamicObject is T)
|
||||
{
|
||||
return this.Updateable((T)updateDynamicObject);
|
||||
|
||||
@@ -26,6 +26,6 @@
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="D:\MyGit\SqlSugar\Src\Asp.NetCore\SqlServerTest\src\SqlSugar\bin\Debug\netstandard1.6\SqlSugar.dll" target="lib\netstandard1.6"></file>
|
||||
<file src="C:\NugetCore\SqlSugar.dll" target="lib\netstandard1.6"></file>
|
||||
</files>
|
||||
</package>
|
||||
@@ -8,6 +8,6 @@ namespace OrmTest
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public static string ConnectionString = @"DataSource=D:\MyGit\SqlSugar\Src\Asp.NetCore\SqlServerTest\src\SqliteTest\DataBase\SqlSugar4xTest.sqlite";
|
||||
public static string ConnectionString = @"DataSource=F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\Src\Asp.NetCore\SqlServerTest\src\SqliteTest\DataBase\SqlSugar4xTest.sqlite";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OrmTest.UnitTest
|
||||
.GroupBy(st => st.Id)
|
||||
.GroupBy((st,sc) => sc.Id).OrderBy(st => st.Id,OrderByType.Asc)
|
||||
.Select((st,sc)=> new { stid=st.Id,scid=sc.Id}).ToSql();
|
||||
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 ",
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OrmTest.UnitTest
|
||||
var t1 = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||
JoinType.Inner,st.Id==sc.Id
|
||||
}).GroupBy(st => st.Id).Having(st => SqlFunc.AggregateAvg(st.Id) == 1).Select(st => new { avgId = SqlFunc.AggregateAvg(st.Id) }).ToSql();
|
||||
base.Check("SELECT AVG(`st`.`ID`) AS `avgId` FROM `STudent` st Inner JOIN School sc ON ( `st`.`ID` = `sc`.`Id` ) GROUP BY `st`.`ID` HAVING (AVG(`st`.`ID`) = @Const0 ) ",
|
||||
base.Check("SELECT AVG(`st`.`ID`) AS `avgId` FROM `STudent` st Inner JOIN School sc ON ( `st`.`ID` = `sc`.`Id` ) GROUP BY `st`.`ID` HAVING (AVG(`st`.`ID`) = @Const0 ) ",
|
||||
new List<SugarParameter>() {
|
||||
new SugarParameter("@Const0",1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user