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

            return((T)query.GetElement(null, ctx, _expression, parameters));
        }
Exemplo n.º 2
0
        private 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);
        }