ArgumentNullException() public static method

使用导致此异常的参数的名称初始化 System.ArgumentNullException 类的新实例。
public static ArgumentNullException ( object checkObj, string message ) : void
checkObj object
message string
return void
Ejemplo n.º 1
0
        public IDeleteable <T> In <PkType>(PkType[] primaryKeyValues)
        {
            if (primaryKeyValues == null || primaryKeyValues.Count() == 0)
            {
                Where(SqlBuilder.SqlFalse);
                return(this);
            }
            string tableName    = this.Context.EntityMaintenance.GetTableName <T>();
            string primaryField = null;

            primaryField = GetPrimaryKeys().FirstOrDefault();
            Check.ArgumentNullException(primaryField, "Table " + tableName + " with no primarykey");
            if (primaryKeyValues.Length < 10000)
            {
                Where(string.Format(DeleteBuilder.WhereInTemplate, SqlBuilder.GetTranslationColumnName(primaryField), primaryKeyValues.ToJoinSqlInVals()));
            }
            else
            {
                if (DeleteBuilder.BigDataInValues == null)
                {
                    DeleteBuilder.BigDataInValues = new List <object>();
                }
                DeleteBuilder.BigDataInValues.AddRange(primaryKeyValues.Select(it => (object)it));
                DeleteBuilder.BigDataFiled = primaryField;
            }
            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取转释后的表名和列名
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        internal static string GetTranslationSqlName(string name)
        {
            Check.ArgumentNullException(name, "表名不能为空。");
            var hasScheme = name.Contains(".");

            if (name.Contains("["))
            {
                return(name);
            }
            if (hasScheme)
            {
                var array = name.Split('.');
                if (array.Length == 2)
                {
                    return(string.Format("[{0}].[{1}]", array.First(), array.Last()));
                }
                else
                {
                    return(string.Join(".", array.Select(it => "[" + it + "]")));
                }
            }
            else
            {
                return("[" + name + "]");
            }
        }
Ejemplo n.º 3
0
        public IUpdateable <T> SetColumns(Expression <Func <T, T> > columns)
        {
            ThrowUpdateByObject();
            var expResult   = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.Update);
            var resultArray = expResult.GetResultArray();

            Check.ArgumentNullException(resultArray, "UpdateColumns Parameter error, UpdateColumns(it=>new T{ it.id=1}) is valid, UpdateColumns(it=>T) is error");
            if (resultArray.HasValue())
            {
                foreach (var item in resultArray)
                {
                    string key   = SqlBuilder.GetNoTranslationColumnName(item);
                    var    value = item;
                    if (value.Contains("= \"SYSDATE\""))
                    {
                        value = value.Replace("= \"SYSDATE\"", "= SYSDATE");
                    }
                    UpdateBuilder.SetValues.Add(new KeyValuePair <string, string>(SqlBuilder.GetTranslationColumnName(key), value));
                }
            }
            this.UpdateBuilder.DbColumnInfoList = UpdateBuilder.DbColumnInfoList.Where(it => (UpdateParameterIsNull == false && IsPrimaryKey(it)) || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
            CheckTranscodeing(false);
            AppendSets();
            return(this);
        }
Ejemplo n.º 4
0
        private static T GetCacheInstance <T>(string className)
        {
            Type type;

            if (typeCache.ContainsKey(className))
            {
                type = typeCache[className];
            }
            else
            {
                lock (typeCache)
                {
                    if (string.IsNullOrEmpty(CustomDllName))
                    {
                        type = assembly.GetType(className);
                    }
                    else
                    {
                        type = GetCustomTypeByClass(className);
                        if (type == null)
                        {
                            type = assembly.GetType(className);
                        }
                    }
                    Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
                    if (!typeCache.ContainsKey(className))
                    {
                        typeCache.Add(className, type);
                    }
                }
            }
            var result = (T)Activator.CreateInstance(type, true);

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 设置查询列执行查询,并且将结果集转成DataTable
        /// </summary>
        /// <param name="sqlable"></param>
        /// <param name="fileds">查询列</param>
        /// <param name="whereObj">SQL参数,例如:new{id=1,name="张三"}</param>
        /// <returns></returns>
        public static DataTable SelectToDataTable(this Sqlable sqlable, string fileds, object whereObj = null)
        {
            StringBuilder sbSql = new StringBuilder(sqlable.Sql.ToString());

            try
            {
                Check.ArgumentNullException(sqlable.Sql, "语法错误,SelectToSql必需要在.Form后面使用");
                sbSql.Insert(0, string.Format("SELECT {0} ", fileds));
                sbSql.Append(" WHERE 1=1").Append(string.Join(" ", sqlable.Where));
                sbSql.Append(sqlable.OrderBy);
                sbSql.Append(sqlable.GroupBy);
                var sqlParams = GetAllParas(sqlable, whereObj);
                var reval     = sqlable.DB.GetDataTable(sbSql.ToString(), sqlParams);
                return(reval);
            }
            catch (Exception ex)
            {
                Check.Exception(true, "sql:{0} \r\n message:{1}", sbSql.ToString(), ex.Message);
                throw;
            }
            finally
            {
                sqlable = null;
                sbSql   = null;
            }
        }
Ejemplo n.º 6
0
        public override string GetTranslationTableName(string name)
        {
            Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
            var context = this.Context;

            var mappingInfo = context
                              .MappingTables
                              .FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase));

            name = (mappingInfo == null ? name : mappingInfo.DbTableName);
            if (name.Contains(".") && !name.Contains("(") && !name.Contains("\".\""))
            {
                return(string.Join(".", name.ToLower(isAutoToLower).Split('.').Select(it => SqlTranslationLeft + it + SqlTranslationRight)));
            }
            else if (name.Contains("("))
            {
                return(name);
            }
            else if (name.Contains(SqlTranslationLeft) && name.Contains(SqlTranslationRight))
            {
                return(name);
            }
            else
            {
                return(SqlTranslationLeft + name.ToLower(isAutoToLower).TrimEnd('"').TrimStart('"') + SqlTranslationRight);
            }
        }
        public override string GetTranslationTableName(string entityName, bool isMapping = true)
        {
            Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
            if (IsTranslationText(entityName))
            {
                return(entityName);
            }
            isMapping = isMapping && this.MappingTables.HasValue();
            var isComplex = entityName.Contains(UtilConstants.Dot);

            if (isMapping && isComplex)
            {
                var columnInfo  = entityName.Split(UtilConstants.DotChar);
                var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase));
                if (mappingInfo != null)
                {
                    columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName;
                }
                return(string.Join(UtilConstants.Dot, columnInfo.Select(it => GetTranslationText(it))));
            }
            else if (isMapping)
            {
                var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
                return(SqlTranslationLeft + (mappingInfo == null ? entityName : mappingInfo.DbTableName).ToLower(isAutoToLower) + SqlTranslationRight);
            }
            else if (isComplex)
            {
                return(string.Join(UtilConstants.Dot, entityName.Split(UtilConstants.DotChar).Select(it => GetTranslationText(it))));
            }
            else
            {
                return(GetTranslationText(entityName));
            }
        }
Ejemplo n.º 8
0
        public virtual string GetTranslationTableName(string name)
        {
            Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
            if (name.IsContainsIn("(", ")", SqlTranslationLeft))
            {
                return(name);
            }
            var context     = this.Context;
            var mappingInfo = context
                              .MappingTables
                              .FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase));

            name = (mappingInfo == null ? name : mappingInfo.DbTableName);
            if (name.IsContainsIn("(", ")", SqlTranslationLeft))
            {
                return(name);
            }
            if (name.Contains("."))
            {
                return(string.Join(".", name.Split('.').Select(it => SqlTranslationLeft + it + SqlTranslationRight)));
            }
            else
            {
                return(SqlTranslationLeft + name + SqlTranslationRight);
            }
        }
Ejemplo n.º 9
0
        public SqlSugarClient(ConnectionConfig config)
        {
            this.Context = this;
            this.CurrentConnectionConfig = config;
            this.ContextID = Guid.NewGuid();

            Console.WriteLine("sqlid:" + this.ContextID);

            Check.ArgumentNullException(config, "config is null");
            switch (config.DbType)
            {
            case DbType.MySql:
                DependencyManagement.TryMySqlData();
                break;

            case DbType.SqlServer:
                break;

            case DbType.Sqlite:
                DependencyManagement.TrySqlite();
                break;

            case DbType.Oracle:
                DependencyManagement.TryOracle();
                break;

            case DbType.PostgreSQL:
                DependencyManagement.TryPostgreSQL();
                break;

            default:
                throw new Exception("ConnectionConfig.DbType is null");
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 反回记录数
        /// </summary>
        /// <param name="sqlable"></param>
        /// <param name="whereObj">匿名参数 (例如:new{id=1,name="张三"})</param>
        /// <param name="preSql">在这语句之前可插入自定义SQL</param>
        /// <param name="nextSql">在这语句之后可以插自定义SQL</param>
        /// <returns></returns>
        public static int Count(this Sqlable sqlable, object whereObj = null, string preSql = null, string nextSql = null)
        {
            StringBuilder sbSql = new StringBuilder(sqlable.Sql.ToString());

            try
            {
                Check.ArgumentNullException(sqlable.Sql, "语法错误,Count必需要在.Form后面使用");
                sbSql.Insert(0, string.Format("SELECT COUNT(1) "));
                sbSql.Append(" WHERE 1=1").Append(string.Join(" ", sqlable.Where));
                sbSql.Append(sqlable.OrderBy);
                sbSql.Append(sqlable.GroupBy);
                var sqlParams = GetAllParas(sqlable, whereObj);
                if (preSql != null)
                {
                    sbSql.Insert(0, preSql);
                }
                if (nextSql != null)
                {
                    sbSql.Append(nextSql);
                }
                return(sqlable.DB.GetInt(sbSql.ToString(), sqlParams));
            }
            catch (Exception ex)
            {
                Check.Exception(true, "sql:{0} \r\n message:{1}", sbSql.ToString(), ex.Message);
                throw;
            }
            finally
            {
                sqlable = null;
                sbSql   = null;
            }
        }
Ejemplo n.º 11
0
        public SqlSugarClient(ConnectionConfig config)
        {
            base.Context = this;
            base.CurrentConnectionConfig = config;
            base.ContextID = Guid.NewGuid();
            Check.ArgumentNullException(config, "config is null");
            switch (config.DbType)
            {
            case DbType.MySql:
                DependencyManagement.TryMySqlData();
                break;

            case DbType.SqlServer:
                break;

            case DbType.Sqlite:
                DependencyManagement.TrySqlite();
                break;

            case DbType.Oracle:
                DependencyManagement.TryOracle();
                break;

            case DbType.PostgreSQL:
                throw new Exception("Development 50%");

            default:
                throw new Exception("ConnectionConfig.DbType is null");
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 设置查询列和分页参数执行查询,并且将结果集转成DataTable
        /// </summary>
        /// <param name="sqlable"></param>
        /// <param name="fileds">查询列</param>
        /// <param name="orderByFiled">Order By字段,可以多个</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示数量</param>
        /// <param name="whereObj">SQL参数,例如:new{id=1,name="张三"}</param>
        /// <returns></returns>
        public static DataTable SelectToPageTable(this Sqlable sqlable, string fileds, string orderByFiled, int pageIndex, int pageSize, object whereObj = null)
        {
            StringBuilder sbSql = new StringBuilder(sqlable.Sql.ToString());

            try
            {
                if (pageIndex == 0)
                {
                    pageIndex = 1;
                }
                Check.ArgumentNullException(sqlable.Sql, "语法错误,SelectToSql必需要在.Form后面使用");
                SqlSugarTool.GetSqlableSql(sqlable, fileds, orderByFiled, pageIndex, pageSize, sbSql);
                var sqlParams = GetAllParas(sqlable, whereObj);
                var reval     = sqlable.DB.GetDataTable(sbSql.ToString(), sqlParams);
                return(reval);
            }
            catch (Exception ex)
            {
                Check.Exception(true, "sql:{0} \r\n message:{1}", sbSql.ToString(), ex.Message);
                throw;
            }
            finally
            {
                sbSql   = null;
                sqlable = null;
            }
        }
Ejemplo n.º 13
0
        private static Restult CreateInstance <Restult>(string className, params Type[] types)
        {
            var  cacheKey = className + string.Join(",", types.Select(it => it.FullName));
            Type type;

            if (typeCache.ContainsKey(cacheKey))
            {
                type = typeCache[cacheKey];
            }
            else
            {
                lock (typeCache)
                {
                    type = Type.GetType(className + "`" + types.Length, true).MakeGenericType(types);
                    Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
                    if (!typeCache.ContainsKey(cacheKey))
                    {
                        typeCache.Add(cacheKey, type);
                    }
                }
            }
            var result = (Restult)Activator.CreateInstance(type, true);

            return(result);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 设置查询列执行查询,并且将结果集转成List《T》
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sqlable"></param>
        /// <param name="fileds">查询列</param>
        /// <param name="whereObj">SQL参数,例如:new{id=1,name="张三"}</param>
        /// <param name="preSql">在这语句之前可插入自定义SQL</param>
        /// <param name="nextSql">在这语句之后可以插自定义SQL</param>
        /// <returns></returns>
        public static List <T> SelectToList <T>(this Sqlable sqlable, string fileds, object whereObj = null, string preSql = null, string nextSql = null) where T : class
        {
            StringBuilder sbSql = new StringBuilder(sqlable.Sql.ToString());

            try
            {
                Check.ArgumentNullException(sqlable.Sql, "语法错误,SelectToSql必需要在.Form后面使用");
                sbSql.Insert(0, string.Format("SELECT {0} ", fileds));
                sbSql.Append(" WHERE 1=1").Append(string.Join(" ", sqlable.Where));
                sbSql.Append(sqlable.OrderBy);
                sbSql.Append(sqlable.GroupBy);
                var sqlParams = GetAllParas(sqlable, whereObj);
                if (preSql != null)
                {
                    sbSql.Insert(0, preSql);
                }
                if (nextSql != null)
                {
                    sbSql.Append(nextSql);
                }
                var reval = SqlSugarTool.DataReaderToList <T>(typeof(T), sqlable.DB.GetReader(sbSql.ToString(), sqlParams), fileds);
                return(reval);
            }
            catch (Exception ex)
            {
                Check.Exception(true, "sql:{0} \r\n message:{1}", sbSql.ToString(), ex.Message);
                throw;
            }
            finally
            {
                sqlable = null;
                sbSql   = null;
            }
        }
Ejemplo n.º 15
0
        public SqlSugarClient(ConnectionConfig config)
        {
            base.Context = this;
            base.CurrentConnectionConfig = config;
            Check.ArgumentNullException(config, "config is null");
            switch (config.DbType)
            {
            case DbType.MySql:
                DependencyManagement.TryMySqlData();
                break;

            case DbType.SqlServer:
                break;

            case DbType.Sqlite:
                DependencyManagement.TrySqlite();
                break;

            case DbType.Oracle:
                //throw new Exception("Oracle developed 75%,to be continued");
                break;

            default:
                throw new Exception("ConnectionConfig.DbType is null");
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 设置查询列和分页参数执行查询,并且将结果集转成List《T》
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sqlable"></param>
        /// <param name="fileds">查询列</param>
        /// <param name="orderByFiled">Order By字段,可以多个</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示数量</param>
        /// <param name="whereObj">SQL参数,例如:new{id=1,name="张三"}</param>
        /// <returns></returns>
        public static List <T> SelectToPageList <T>(this Sqlable sqlable, string fileds, string orderByFiled, int pageIndex, int pageSize, object whereObj = null) where T : class
        {
            StringBuilder sbSql = new StringBuilder(sqlable.Sql.ToString());

            try
            {
                if (pageIndex == 0)
                {
                    pageIndex = 1;
                }
                Check.ArgumentNullException(sqlable.Sql, "语法错误,SelectToSql必需要在.Form后面使用");
                sbSql.Insert(0, string.Format("SELECT {0},row_index=ROW_NUMBER() OVER(ORDER BY {1} )", fileds, orderByFiled));
                sbSql.Append(" WHERE 1=1 ").Append(string.Join(" ", sqlable.Where));
                sbSql.Append(sqlable.OrderBy);
                sbSql.Append(sqlable.GroupBy);
                int skip = (pageIndex - 1) * pageSize + 1;
                int take = pageSize;
                sbSql.Insert(0, "SELECT * FROM ( ");
                sbSql.AppendFormat(") t WHERE  t.row_index BETWEEN {0}  AND {1}   ", skip, skip + take - 1);
                var sqlParams = SqlSugarTool.GetParameters(whereObj);
                var reval     = SqlSugarTool.DataReaderToList <T>(typeof(T), sqlable.DB.GetReader(sbSql.ToString(), sqlParams), fileds);
                return(reval);
            }
            catch (Exception ex)
            {
                Check.Exception(true, "sql:{0} \r\n message:{1}", sbSql.ToString(), ex.Message);
                throw;
            }
            finally
            {
                sbSql   = null;
                sqlable = null;
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Join
 /// </summary>
 /// <param name="sqlable"></param>
 /// <param name="tableName">表名字符串</param>
 /// <param name="shortName">表名简写</param>
 /// <param name="leftFiled">join左边连接字段</param>
 /// <param name="RightFiled">join右边连接字段</param>
 /// <param name="type">join类型</param>
 /// <returns></returns>
 public static Sqlable.Sqlable Join(this Sqlable.Sqlable sqlable, string tableName, string shortName, string leftFiled,
                                    string RightFiled, JoinType type)
 {
     Check.ArgumentNullException(sqlable.Sql, "语法错误,正确用法:sqlable.Form(“table”).Join");
     sqlable.Sql.AppendFormat(" {0} JOIN {1} {2}  {3} ON  {4} = {5} ", type, tableName.GetTranslationSqlName(),
                              shortName, sqlable.DB.IsNoLock.GetLockString(), leftFiled, RightFiled);
     return(sqlable);
 }
Ejemplo n.º 18
0
 public ISugarQueryable <T> CreateMapping <T>() where T : class, new()
 {
     Check.ArgumentNullException(Context, "Please use Sqlugar.ModelContext");
     using (Context)
     {
         return(Context.Queryable <T>());
     }
 }
Ejemplo n.º 19
0
        public IDeleteable <T> Where(List <T> deleteObjs)
        {
            if (deleteObjs == null || deleteObjs.Count() == 0)
            {
                Where(SqlBuilder.SqlFalse);
                return(this);
            }
            string tableName          = this.Context.EntityProvider.GetTableName <T>();
            var    primaryFields      = this.GetPrimaryKeys();
            var    isSinglePrimaryKey = primaryFields.Count == 1;

            Check.ArgumentNullException(primaryFields, string.Format("Table {0} with no primarykey", tableName));
            if (isSinglePrimaryKey)
            {
                List <object> primaryKeyValues = new List <object>();
                var           primaryField     = primaryFields.Single();
                foreach (var deleteObj in deleteObjs)
                {
                    var entityPropertyName = this.Context.EntityProvider.GetPropertyName <T>(primaryField);
                    var columnInfo         = EntityInfo.Columns.Single(it => it.PropertyName.Equals(entityPropertyName, StringComparison.CurrentCultureIgnoreCase));
                    var value = columnInfo.PropertyInfo.GetValue(deleteObj, null);
                    primaryKeyValues.Add(value);
                }
                var inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals();
                Where(string.Format(DeleteBuilder.WhereInTemplate, SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString));
            }
            else
            {
                StringBuilder whereInSql = new StringBuilder();
                foreach (var deleteObj in deleteObjs)
                {
                    StringBuilder orString = new StringBuilder();
                    var           isFirst  = deleteObjs.IndexOf(deleteObj) == 0;
                    if (isFirst)
                    {
                        orString.Append(DeleteBuilder.WhereInOrTemplate + PubConst.Space);
                    }
                    int           i         = 0;
                    StringBuilder andString = new StringBuilder();
                    foreach (var primaryField in primaryFields)
                    {
                        if (i == 0)
                        {
                            andString.Append(DeleteBuilder.WhereInAndTemplate + PubConst.Space);
                        }
                        var entityPropertyName = this.Context.EntityProvider.GetPropertyName <T>(primaryField);
                        var columnInfo         = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName);
                        var entityValue        = columnInfo.PropertyInfo.GetValue(deleteObj, null);
                        andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue);
                        ++i;
                    }
                    orString.AppendFormat(DeleteBuilder.WhereInAreaTemplate, andString);
                    whereInSql.Append(orString);
                }
                Where(string.Format(DeleteBuilder.WhereInAreaTemplate, whereInSql.ToString()));
            }
            return(this);
        }
Ejemplo n.º 20
0
        public override async Task <int> UpdateByTempAsync(string tableName, string tempName, string[] updateColumns, string[] whereColumns)
        {
            Check.ArgumentNullException(!updateColumns.Any(), "update columns count is 0");
            Check.ArgumentNullException(!whereColumns.Any(), "where columns count is 0");
            var    sets   = string.Join(",", updateColumns.Select(it => $"TM.{it}=TE.{it}"));
            var    wheres = string.Join(",", whereColumns.Select(it => $"TM.{it}=TE.{it}"));
            string sql    = string.Format(UpdateSql, sets, tableName, tempName, wheres);

            return(await this.Context.Ado.ExecuteCommandAsync(sql));
        }
Ejemplo n.º 21
0
        public override async Task <int> UpdateByTempAsync(string tableName, string tempName, string[] updateColumns, string[] whereColumns)
        {
            var sqlquerybulder = this.Context.Queryable <object>().SqlBuilder;

            Check.ArgumentNullException(!updateColumns.Any(), "update columns count is 0");
            Check.ArgumentNullException(!whereColumns.Any(), "where columns count is 0");
            var    sets   = string.Join(",", updateColumns.Select(it => $"{sqlquerybulder.GetTranslationColumnName(it)}=TE.{sqlquerybulder.GetTranslationColumnName(it)}"));
            var    wheres = string.Join(",", whereColumns.Select(it => $"{tableName}.{sqlquerybulder.GetTranslationColumnName(it)}=TE.{sqlquerybulder.GetTranslationColumnName(it)}"));
            string sql    = string.Format(UpdateSql, sets, tableName, tempName, wheres);

            return(await this.Context.Ado.ExecuteCommandAsync(sql));
        }
Ejemplo n.º 22
0
        public override string GetTranslationColumnName(string entityName, string propertyName)
        {
            Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
            Check.ArgumentNullException(propertyName, string.Format(ErrorMessage.ObjNotExist, "Column Name"));
            var context     = this.Context;
            var mappingInfo = context
                              .MappingColumns
                              .FirstOrDefault(it =>
                                              it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase) &&
                                              it.PropertyName.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase));

            return(mappingInfo == null ? "[" + propertyName + "]" : "[" + mappingInfo.DbColumnName + "]");
        }
Ejemplo n.º 23
0
        public void CreateClassFile(string directoryPath, string nameSpace = "Models")
        {
            Check.ArgumentNullException(directoryPath, "directoryPath can't null");
            var classStringList = ToClassStringList(nameSpace);

            if (classStringList.IsValuable())
            {
                foreach (var item in classStringList)
                {
                    FileHelper.CreateFile(directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format("\\{0}.cs", item.Key), item.Value, Encoding.UTF8);
                }
            }
        }
Ejemplo n.º 24
0
        public override string GetTranslationTableName(string name)
        {
            if (name.Contains("`"))
            {
                return(name);
            }
            Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
            var context     = this.Context;
            var mappingInfo = context
                              .MappingTables
                              .FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase));

            return("`" + (mappingInfo == null ? name : mappingInfo.DbTableName) + "`");
        }
Ejemplo n.º 25
0
        public IDeleteable <T> In <PkType>(PkType[] primaryKeyValues)
        {
            if (primaryKeyValues == null || primaryKeyValues.Count() == 0)
            {
                Where(SqlBuilder.SqlFalse);
                return(this);
            }
            string tableName    = this.Context.EntityProvider.GetTableName <T>();
            string primaryField = null;

            primaryField = GetPrimaryKeys().FirstOrDefault();
            Check.ArgumentNullException(primaryField, "Table " + tableName + " with no primarykey");
            Where(string.Format(DeleteBuilder.WhereInTemplate, SqlBuilder.GetTranslationColumnName(primaryField), primaryKeyValues.ToJoinSqlInVals()));
            return(this);
        }
Ejemplo n.º 26
0
        public void CreateClassFile(string directoryPath, string nameSpace = "Models")
        {
            var seChar = Path.DirectorySeparatorChar.ToString();

            Check.ArgumentNullException(directoryPath, "directoryPath can't null");
            var classStringList = ToClassStringList(nameSpace);

            if (classStringList.IsValuable())
            {
                foreach (var item in classStringList)
                {
                    var filePath = directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format(seChar + "{0}.cs", item.Key);
                    FileHelper.CreateFile(filePath, item.Value, Encoding.UTF8);
                }
            }
        }
Ejemplo n.º 27
0
        public IUpdateable <T> UpdateColumns(Expression <Func <T, T> > columns)
        {
            var expResult   = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.Update);
            var resultArray = expResult.GetResultArray();

            Check.ArgumentNullException(resultArray, "UpdateColumns Parameter error, UpdateColumns(it=>new T{ it.id=1}) is valid, UpdateColumns(it=>T) is error");
            if (resultArray.HasValue())
            {
                foreach (var item in resultArray)
                {
                    string key = SqlBuilder.GetNoTranslationColumnName(item);
                    UpdateBuilder.SetValues.Add(new KeyValuePair <string, string>(SqlBuilder.GetTranslationColumnName(key), item));
                }
            }
            this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
            return(this);
        }
Ejemplo n.º 28
0
 public virtual string GetTranslationColumnName(string columnName)
 {
     Check.ArgumentNullException(columnName, string.Format(ErrorMessage.ObjNotExist, "column Name"));
     if (columnName.Substring(0, 1) == this.SqlParameterKeyWord)
     {
         return(columnName);
     }
     if (IsTranslationText(columnName))
     {
         return(columnName);
     }
     if (columnName.Contains("."))
     {
         return(string.Join(".", columnName.Split('.').Select(it => GetTranslationText(it))));
     }
     else
     {
         return(GetTranslationText(columnName));
     }
 }
 public override string GetTranslationColumnName(string columnName)
 {
     Check.ArgumentNullException(columnName, string.Format(ErrorMessage.ObjNotExist, "Column Name"));
     if (columnName.Substring(0, 1) == this.SqlParameterKeyWord)
     {
         return(columnName);
     }
     if (IsTranslationText(columnName))
     {
         return(columnName);
     }
     if (columnName.Contains(UtilConstants.Dot))
     {
         return(string.Join(UtilConstants.Dot, columnName.Split(UtilConstants.DotChar).Select(it => GetTranslationText(it))));
     }
     else
     {
         return(GetTranslationText(columnName));
     }
 }
Ejemplo n.º 30
0
        /// <summary>
        /// 根据主键查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queryable"></param>
        /// <param name="pkValues">主键集合</param>
        /// <returns></returns>
        public static Queryable <T> In <T>(this Queryable <T> queryable, params object[] pkValues)
        {
            Check.Exception(pkValues == null || pkValues.Length == 0, "In.pkValues的Count不能为0");
            var type = pkValues[0].GetType();

            if (type != SqlSugarTool.IntType && type != SqlSugarTool.GuidType && type.FullName.IsCollectionsList())
            {
                var newList = new List <object>();
                foreach (var item in (IEnumerable)pkValues[0])
                {
                    newList.Add(item);
                }
                pkValues = newList.ToArray();
                Check.Exception(pkValues == null || pkValues.Length == 0, "In.pkValues的Count不能为0");
            }
            var pkName = SqlSugarTool.GetPrimaryKeyByTableName(queryable.DB, queryable.TableName);

            queryable.OrderByValue = null;
            Check.ArgumentNullException(pkName, "In(params object[]PkValue)查询表中不存在主键,请换In的其它重载方法。");
            return(queryable.In <T, string>(pkName, pkValues.Select(it => it.ToString()).ToArray()));
        }