Exemplo n.º 1
0
        public T Execute(object[] parameters)
        {
            var db  = (IDataContext)parameters[0];
            var ctx = DataContextInfo.Create(db);

            return((T)GetInfo(db).GetElement(null, ctx, _expression, parameters));
        }
Exemplo n.º 2
0
        public static int InsertOrReplace <T>(this IDataContext dataContext, IEnumerable <T> objs)
        {
            int cnt = 0;

            foreach (var obj in objs)
            {
                cnt += Query <T> .InsertOrReplace(DataContextInfo.Create(dataContext), obj);
            }
            return(cnt);
        }
Exemplo n.º 3
0
        Query <T> GetInfo(IDataContext dataContext)
        {
            var dataContextInfo = DataContextInfo.Create(dataContext);

            string        lastContextID;
            MappingSchema lastMappingSchema;
            Query <T>     query;

            lock (_sync)
            {
                lastContextID     = _lastContextID;
                lastMappingSchema = _lastMappingSchema;
                query             = _lastQuery;
            }

            var contextID     = dataContextInfo.ContextID;
            var mappingSchema = dataContextInfo.MappingSchema;

            if (lastContextID != contextID || lastMappingSchema != mappingSchema)
            {
                query = null;
            }

            if (query == null)
            {
                var key = new { contextID, mappingSchema };

                lock (_sync)
                    _infos.TryGetValue(key, out query);

                if (query == null)
                {
                    lock (_sync)
                    {
                        _infos.TryGetValue(key, out query);

                        if (query == null)
                        {
                            query = new ExpressionBuilder(new Query <T>(), dataContextInfo, _expression, _lambda.Parameters.ToArray())
                                    .Build <T>();

                            _infos.Add(key, query);

                            _lastContextID     = contextID;
                            _lastMappingSchema = mappingSchema;
                            _lastQuery         = query;
                        }
                    }
                }
            }

            return(query);
        }
Exemplo n.º 4
0
 public static int Delete <T>([NotNull] this IDataContext dataContext, T obj)
 {
     return(Query <T> .Delete(DataContextInfo.Create(dataContext), obj));
 }
Exemplo n.º 5
0
 public static int Update <T>(this IDataContext dataContext, T obj)
 {
     return(Query <T> .Update(DataContextInfo.Create(dataContext), obj));
 }
Exemplo n.º 6
0
 public static object InsertWithOutput <T>(this IDataContext dataContext, T obj)
 {
     return(Query <T> .InsertWithOutput(DataContextInfo.Create(dataContext), obj));
 }
Exemplo n.º 7
0
 public static int InsertOrReplace <T>(this IDataContext dataContext, T obj)
 {
     return(Query <T> .InsertOrReplace(DataContextInfo.Create(dataContext), obj));
 }