Пример #1
0
        public PropertyStore Get(Type type, object id)
        {
            if (id != null && !(id is string))
            {
                throw new ArgumentException("Invalid id type " + id.GetType().FullName);
            }

            var query = QueryBuilderFactory.Instance.Create();

            query.SqlConditionals.Add("DataType = @dataType");
            query.SqlParameters.Add("@dataType", type.FullName);

            if (id != null)
            {
                query.SqlConditionals.Add("Path = @path");
                query.SqlParameters.Add("@path", id);
            }
            else
            {
                query.SqlConditionals.Add("Path IS NULL");
            }

            query = ProcessQueryGet.Process(query);

            query.SelectModifier = "TOP 1";
            query.SqlTable       = "ContentItems";
            return(query.RunSelect().FirstOrDefault());
        }
Пример #2
0
        public IEnumerable <PropertyStore> Get(Type type, Dictionary <string, object> clauses, List <string> fields, bool excludeFields)
        {
            var query = QueryBuilderFactory.Instance.Create();

            bool isSummary = typeof(Summary).IsAssignableFrom(type);

            if (clauses.ContainsKey("@Types"))
            {
                query.SqlConditionals.Add("DataType IN ("
                                          + ((List <Type>)clauses["@Types"]).Select(sc => query.QuoteString(sc.FullName)).Join(",")
                                          + ")");
            }
            else
            {
                query.SqlConditionals.Add("DataType = @dataType");
                if (clauses.ContainsKey("@Type"))
                {
                    query.SqlParameters.Add("@dataType", ((Type)clauses["@Type"]).FullName);
                }
                else
                {
                    query.SqlParameters.Add("@dataType", type.FullName);
                }
            }

            foreach (var kvp in clauses)
            {
                if ("@Types @Type".Contains(kvp.Key))
                {
                    continue;
                }

                query.SqlConditionals.Add(kvp.Key);
                query.SqlParameters.Add("@" + kvp.Key.After("@").UpTo(" "), kvp.Value);
            }

            query = ProcessQueryGet.Process(query);

            if (excludeFields)
            {
                query.SqlFields.AddRange(GetFieldList().Except(fields));
            }
            else
            {
                query.SqlFields.AddRange(fields);
            }

            // Don't get content field for summaries
            if (isSummary && query.SqlFields.Contains("Content"))
            {
                query.SqlFields.Remove("Content");
            }

            query.SqlTable = "ContentItems";
            return(query.RunSelect());
        }
Пример #3
0
        public int GetCount(Type type, Dictionary <string, object> clauses)
        {
            var query = QueryBuilderFactory.Instance.Create();

            foreach (var kvp in clauses)
            {
                query.SqlConditionals.Add(kvp.Key);
                query.SqlParameters.Add("@" + kvp.Key.After("@").UpTo(" "), kvp.Value);
            }

            query          = ProcessQueryGet.Process(query);
            query.SqlTable = GetTableName(type);
            return(query.RunCount());
        }
Пример #4
0
        public PropertyStore Get(Type type, object id)
        {
            string idName = GetIdName(type);
            object idConv = ConvertForField(type, idName, id);
            var    query  = QueryBuilderFactory.Instance.Create();

            query.SqlConditionals.Add(idName + " = @id");
            query.SqlParameters.Add("@id", idConv);

            query = ProcessQueryGet.Process(query);

            query.SelectModifier = "TOP 1";
            query.SqlTable       = GetTableName(type);
            return(query.RunSelect().FirstOrDefault());
        }
Пример #5
0
        public IEnumerable <PropertyStore> Get(Type type, IEnumerable <object> ids)
        {
            if (!ids.Any())
            {
                return(new List <PropertyStore>());
            }

            var           query        = QueryBuilderFactory.Instance.Create();
            List <string> idParamNames = Enumerable.Range(0, ids.Count()).Select(n => "@id" + n).ToList();
            string        idName       = GetIdName(type);

            query.SqlConditionals.Add(idName + " IN (" + idParamNames.Join(", ") + ")");
            ids.Select((id, n) => new KeyValuePair <string, string>(idParamNames[n], id as string))
            .Do(kvp => query.SqlParameters.Add(kvp.Key, kvp.Value));

            query = ProcessQueryGet.Process(query);

            query.SelectModifier = "TOP " + ids.Count().ToString();
            query.SqlTable       = GetTableName(type);
            return(query.RunSelect());
        }