Exemple #1
0
        private void InitContext(ConnectionConfig config)
        {
            var aopIsNull = config.AopEvents == null;

            if (aopIsNull)
            {
                config.AopEvents = new AopEvents();
            }
            _Context = new SqlSugarProvider(config);
            if (!aopIsNull)
            {
                _Context.Ado.IsEnableLogEvent = true;
            }
            this.CurrentConnectionConfig = config;
            _ThreadId = Thread.CurrentThread.ManagedThreadId.ToString();
            if (_MappingColumns == null)
            {
                this.MappingTables = new MappingTableList();
            }
            if (this.MappingColumns == null)
            {
                this.MappingColumns = new MappingColumnList();
            }
            if (this.IgnoreColumns == null)
            {
                this.IgnoreColumns = new IgnoreColumnList();
            }
            if (this.IgnoreInsertColumns == null)
            {
                this.IgnoreInsertColumns = new IgnoreColumnList();
            }
        }
        private SqlSugarProvider GetContext()
        {
            SqlSugarProvider result = null;

            if (IsSameThreadAndShard())
            {
                result = SameThreadAndShard();
            }
            else if (IsNoSameThreadAndShard())
            {
                result = NoSameThreadAndShard();
            }
            else if (IsSynchronization())
            {
                result = Synchronization();
            }
            else if (IsSingleInstanceAsync())
            {
                result = Synchronization();//Async no support  Single Instance
            }
            else if (IsAsync())
            {
                result = Synchronization();
            }
            else
            {
                IsSingleInstance = true;
                result           = NoSameThread();
            }
            if (result.Root == null)
            {
                result.Root = this;
            }
            return(result);
        }
 public IDataReaderEntityBuilder(SqlSugarProvider context, IDataRecord dataRecord, List <string> fieldNames)
 {
     this.Context        = context;
     this.DataRecord     = dataRecord;
     this.DynamicBuilder = new IDataReaderEntityBuilder <T>();
     this.ReaderKeys     = fieldNames;
 }
Exemple #4
0
        protected async Task <List <T> > GetEntityListAsync <T>(SqlSugarProvider context, IDataReader dataReader)
        {
            Type   type       = typeof(T);
            var    fieldNames = GetDataReaderNames(dataReader);
            string cacheKey   = GetCacheKey(type, fieldNames);
            IDataReaderEntityBuilder <T> entytyList = context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, () =>
            {
                var cacheResult = new IDataReaderEntityBuilder <T>(context, dataReader, fieldNames).CreateBuilder(type);
                return(cacheResult);
            });
            List <T> result = new List <T>();

            try
            {
                if (dataReader == null)
                {
                    return(result);
                }
                while (await((DbDataReader)dataReader).ReadAsync())
                {
                    result.Add(entytyList.Build(dataReader));
                }
            }
            catch (Exception ex)
            {
                Check.Exception(true, ErrorMessage.EntityMappingError, ex.Message);
            }
            return(result);
        }
Exemple #5
0
 private void InitTenant(SugarTenant Tenant)
 {
     if (Tenant.Context == null)
     {
         Tenant.Context = new SqlSugarProvider(Tenant.ConnectionConfig);
     }
     _Context = Tenant.Context;
     this.CurrentConnectionConfig = Tenant.ConnectionConfig;
 }
Exemple #6
0
        public static CacheKey GetKey(SqlSugarProvider context, QueryBuilder queryBuilder)
        {
            CacheKey result = new CacheKey();

            result.Database = context.Context.Ado.Connection.Database;
            AddTables(context, queryBuilder, result);
            AddIdentificationList(queryBuilder, result);
            return(result);
        }
Exemple #7
0
 internal SaveableProvider(SqlSugarProvider context, T saveObject)
 {
     this.saveObjects = new List <T>()
     {
         saveObject
     };
     this.Context = context;
     this.Context.InitMappingInfo <T>();
 }
Exemple #8
0
 public SqlSugarException(SqlSugarProvider context, Exception ex, string sql, object pars)
     : base(ex.Message)
 {
     this.Sql            = sql;
     this.Parametres     = pars;
     this.InnerException = ex.InnerException;
     this.StackTrace     = ex.StackTrace;
     this.TargetSite     = ex.TargetSite;
     this.Source         = ex.Source;
 }
Exemple #9
0
        private SqlSugarProvider CopyClient()
        {
            var result = new SqlSugarProvider(this.CurrentConnectionConfig);

            result.MappingColumns      = _MappingColumns;
            result.MappingTables       = _MappingTables;
            result.IgnoreColumns       = _IgnoreColumns;
            result.IgnoreInsertColumns = _IgnoreInsertColumns;

            return(result);
        }
Exemple #10
0
 public Storageable(List <T> datas, SqlSugarProvider context)
 {
     this.Context = context;
     if (datas == null)
     {
         datas = new List <T>();
     }
     this.allDatas = datas.Select(it => new StorageableInfo <T>()
     {
         Item = it
     }).ToList();
 }
 internal SplitTableContext(SqlSugarProvider context)
 {
     this.Context = context;
     if (this.Context.CurrentConnectionConfig.ConfigureExternalServices != null && this.Context.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService != null)
     {
         Service = this.Context.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService;
     }
     else
     {
         Service = new DateSplitTableService();
     }
 }
 private MapperExpressionInfo GetFillInfo(Expression childExpression, MapperExpression mapper)
 {
     this.querybuiler = mapper.QueryBuilder;
     this.context     = mapper.Context;
     this.sqlBuilder  = mapper.SqlBuilder;
     if (this.querybuiler.TableShortName.IsNullOrEmpty())
     {
         this.querybuiler.TableShortName = (childExpression as MemberExpression).Expression.ToString();
     }
     this.context.InitMappingInfo(childExpression.Type);
     return(new MapperExpressionInfo()
     {
         EntityInfo = this.context.EntityMaintenance.GetEntityInfo(childExpression.Type)
     });
 }
Exemple #13
0
        public SqlSugarProvider CopyContext(bool isCopyEvents = false)
        {
            var newClient = new SqlSugarProvider(this.TranslateCopy(Context.CurrentConnectionConfig));

            newClient.CurrentConnectionConfig.ConfigureExternalServices = Context.CurrentConnectionConfig.ConfigureExternalServices;
            newClient.MappingColumns      = this.TranslateCopy(Context.MappingColumns);
            newClient.MappingTables       = this.TranslateCopy(Context.MappingTables);
            newClient.IgnoreColumns       = this.TranslateCopy(Context.IgnoreColumns);
            newClient.IgnoreInsertColumns = this.TranslateCopy(Context.IgnoreInsertColumns);
            if (isCopyEvents)
            {
                newClient.QueryFilter = Context.QueryFilter;
                newClient.CurrentConnectionConfig.AopEvents = Context.CurrentConnectionConfig.AopEvents;
            }
            return(newClient);
        }
        private SqlSugarProvider GetContext()
        {
            SqlSugarProvider result = null;

            //if (IsSameThreadAndShard())
            //{
            //    result = SameThreadAndShard();
            //}
            //else if (IsNoSameThreadAndShard())
            //{
            //    result = NoSameThreadAndShard();
            //}
            //else
            //{
            result = Synchronization();
            //}
            ///Because SqlSugarScope implements thread safety
            //else if (IsSingleInstanceAsync())
            //{
            //    result = Synchronization();//Async no support  Single Instance
            //}
            //else if (IsAsync())
            //{
            //    result = Synchronization();
            //}
            //else
            //{
            //    StackTrace st = new StackTrace(true);
            //    var methods = st.GetFrames();
            //    var isAsync = UtilMethods.IsAnyAsyncMethod(methods);
            //    if (isAsync)
            //    {
            //        result = Synchronization();
            //    }
            //    else
            //    {
            //        result = NoSameThread();
            //    }
            //}
            if (result.Root == null)
            {
                result.Root = this;
            }
            return(result);
        }
Exemple #15
0
        private SqlSugarProvider GetContext()
        {
            SqlSugarProvider result = null;

            if (IsSameThreadAndShard())
            {
                result = SameThreadAndShard();
            }
            else if (IsNoSameThreadAndShard())
            {
                result = NoSameThreadAndShard();
            }
            else if (IsSynchronization())
            {
                result = Synchronization();
            }
            else if (IsSingleInstanceAsync())
            {
                result = Synchronization();//Async no support  Single Instance
            }
            else if (IsAsync())
            {
                result = Synchronization();
            }
            else
            {
                StackTrace st      = new StackTrace(true);
                var        methods = st.GetFrames();
                var        isAsync = UtilMethods.IsAnyAsyncMethod(methods);
                if (isAsync)
                {
                    result = Synchronization();
                }
                else
                {
                    result = NoSameThread();
                }
            }
            if (result.Root == null)
            {
                result.Root = this;
            }
            return(result);
        }
Exemple #16
0
        public void AddConnection(ConnectionConfig connection)
        {
            Check.ArgumentNullException(connection, "AddConnection.connection can't be null");
            InitTenant();
            var db = this._AllClients.FirstOrDefault(it => it.ConnectionConfig.ConfigId == connection.ConfigId);

            if (db == null)
            {
                if (this._AllClients == null)
                {
                    this._AllClients = new List <SugarTenant>();
                }
                var provider = new SqlSugarProvider(connection);
                if (connection.AopEvents != null)
                {
                    provider.Ado.IsEnableLogEvent = true;
                }
                this._AllClients.Add(new SugarTenant()
                {
                    ConnectionConfig = connection,
                    Context          = provider
                });
            }
        }
Exemple #17
0
 internal SaveableProvider(SqlSugarProvider context, List <T> saveObjects)
 {
     this.saveObjects = saveObjects;
     this.Context     = context;
     this.Context.InitMappingInfo <T>();
 }
 public FastestProvider(SqlSugarProvider sqlSugarProvider)
 {
     this.context   = sqlSugarProvider;
     this.queryable = this.context.Queryable <T>();
     entityInfo     = this.context.EntityMaintenance.GetEntityInfo <T>();
 }
Exemple #19
0
        public static T GetOrCreate <T>(ICacheService cacheService, QueryBuilder queryBuilder, Func <T> getData, int cacheDurationInSeconds, SqlSugarProvider context, string cacheKey)
        {
            CacheKey key = CacheKeyBuider.GetKey(context, queryBuilder);

            key.AppendKey = cacheKey;
            string keyString = key.ToString();
            var    result    = cacheService.GetOrCreate(keyString, getData, cacheDurationInSeconds);

            return(result);
        }
Exemple #20
0
 private void AddCallContext(SqlSugarProvider context)
 {
     CallContext.ContextList.Value = new List <SqlSugarProvider>();
     CallContext.ContextList.Value.Add(context);
 }
Exemple #21
0
 public SqlSugarException(SqlSugarProvider context, string message, string sql)
     : base(message)
 {
     this.Sql = sql;
 }
Exemple #22
0
 public SqlSugarException(SqlSugarProvider context, string message, object pars)
     : base(message)
 {
     this.Parametres = pars;
 }
 public static object GetEntity(this IDataReader dr, SqlSugarProvider context)
 {
     return(null);
 }
Exemple #24
0
 public MySqlBlueCopy(SqlSugarProvider context, ISqlBuilder builder, T [] entitys)
 {
     this.Context = context;
     this.Builder = builder;
     this.Entitys = entitys;
 }
Exemple #25
0
 public AopProvider(SqlSugarProvider context)
 {
     this.Context = context;
     this.Context.Ado.IsEnableLogEvent = true;
 }