Ejemplo n.º 1
0
 public void InsertInToDb <T>(ref T item)
     where T : class, new()
 {
     item = SmartDbEntityAgentFactory.Of(item);
     SmartDbBus.PlanToWriteToDb(item, DbActionType.Insert);
     //return item;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 仅仅添加到缓存
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public T AddCache(T item)
        {
            T agent = SmartDbEntityAgentFactory.Of(item);

            _data.Add(agent);
            return(agent);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 增
        /// </summary>
        public T Insert(ref T item)
        {
            T agent = SmartDbEntityAgentFactory.Of(item);

            _data.Add(agent);
            //记录到案
            this.WriteToDb(agent, DbActionType.Insert);
            item = agent;
            return(agent);
        }
Ejemplo n.º 4
0
 public SmartDbSet(IEnumerable <T> data)
 {
     if (data != null)
     {
         foreach (var item in data)
         {
             T agent = SmartDbEntityAgentFactory.Of(item);
             _data.Add(agent);
         }
     }
 }
Ejemplo n.º 5
0
        public static void PreLoad(string assemblyName)
        {
            var assembly = Assembly.Load(assemblyName);

            foreach (var type in assembly.ExportedTypes)
            {
                if (type.GetCustomAttribute <DataContractAttribute>() != null)
                {
                    var t   = SmartDbEntityAgentFactory.OfType(type);
                    var dbt = QueryDbTypeInfo(t);
                }
            }
        }
Ejemplo n.º 6
0
        public T QueryDbEntity <T>(string sql, object param = null)
            where T : class, new()
        {
            int       retrynumb = 0;
            Exception e         = null;

            do
            {
                try
                {
                    if (_connReader == null)
                    {
                        _connReader = new MySqlConnection(this._connstr);
                        _connReader.Open();
                    }
                    var entity = _connReader.QueryFirstOrDefault <T>(sql, param);
                    if (entity == null)
                    {
                        return(null);
                    }
                    T agent = SmartDbEntityAgentFactory.Of(entity);
                    return(agent);
                }
                catch (Exception ex)
                {
                    e = ex;
                    if (_connReader != null)
                    {
                        _connReader.Dispose();
                    }
                    _connReader = null;
                    retrynumb++;
                }
            } while (retrynumb < 10);
            if (retrynumb >= 10)
            {
                this.UnHandledSqlCommandExecuteException?.Invoke(this, e);
            }
            return(null);
        }