Beispiel #1
0
        private static ICriterion CreateDetailExpression(Parameter p)
        {
            if (p.Comparison == Comparison.NotNull)
            {
                return(Subqueries.PropertyIn("ID",
                                             DetachedCriteria.For <ContentDetail>()
                                             .SetProjection(Projections.Property("EnclosingItem.ID"))
                                             .Add(Expression.Eq("Name", p.Name))));
            }
            if (p.Comparison == Comparison.Null)
            {
                return(Subqueries.PropertyNotIn("ID",
                                                DetachedCriteria.For <ContentDetail>()
                                                .SetProjection(Projections.Property("EnclosingItem.ID"))
                                                .Add(Expression.Eq("Name", p.Name))));
            }

            string propertyName = p.Comparison.HasFlag(Comparison.In)
                ? ContentDetail.GetAssociatedEnumerablePropertyName(p.Value as IEnumerable)
                : ContentDetail.GetAssociatedPropertyName(p.Value);

            var subselect = DetachedCriteria.For <ContentDetail>()
                            .SetProjection(Projections.Property("EnclosingItem.ID"))
                            .Add(CreateExpression(propertyName, ContentDetail.ExtractQueryValue(p.Value), p.Comparison, true));

            if (p.Name != null)
            {
                subselect = subselect.Add(Expression.Eq("Name", p.Name));
            }

            return(Subqueries.PropertyIn("ID", subselect));
        }
Beispiel #2
0
 private static void StoreObjectOnDetails(ContentItem item, string keyPrefix, object entity, DetailCollection collection)
 {
     foreach (var kvp in new RouteValueDictionary(entity))
     {
         if (ContentDetail.GetAssociatedPropertyName(kvp.Value) == "Value")
         {
             StoreObjectOnDetails(item, keyPrefix + "." + kvp.Key, kvp.Value, collection);
         }
         else
         {
             SetDetail(item, collection, keyPrefix + "." + kvp.Key, kvp.Value);
         }
     }
 }
Beispiel #3
0
        public static IMongoQuery CreateQuery(this IParameter parameter)
        {
            if (parameter is ParameterCollection)
            {
                var pc = parameter as ParameterCollection;
                switch (pc.Operator)
                {
                case Operator.And:
                    return(Query.And(pc.Select(p => p.CreateQuery())));

                case Operator.Or:
                    return(Query.Or(pc.Select(p => p.CreateQuery())));

                case Operator.None:
                default:
                    throw new NotSupportedException();
                }
            }
            else if (parameter is Parameter)
            {
                var p = (Parameter)parameter;

                if (p.IsDetail)
                {
                    var valueExpression = GetValueExpression(p.Comparison.HasFlag(Comparison.In)
                                                ? ContentDetail.GetAssociatedEnumerablePropertyName(p.Value as IEnumerable)
                                                : ContentDetail.GetAssociatedPropertyName(p.Value), p.Comparison, p.Value);
                    var detailExpression = (p.Name == null)
                                                ? valueExpression
                                                : Query.And(
                        Query.EQ("Name", p.Name),
                        valueExpression);

                    return(Query.Or(
                               Query.ElemMatch("Details", detailExpression),
                               Query.ElemMatch("DetailCollections.Details", detailExpression)));
                }

                p.Name = p.Name.TranslateProperty();

                return(GetValueExpression(p.Name, p.Comparison, p.Value));
            }
            throw new NotSupportedException();
        }
Beispiel #4
0
        private static ICriterion CreateDetailExpression(Parameter p)
        {
            if (p.Comparison == Comparison.NotNull)
            {
                return(Subqueries.PropertyIn("ID",
                                             DetachedCriteria.For <ContentDetail>()
                                             .SetProjection(Projections.Property("EnclosingItem.ID"))
                                             .Add(Expression.Eq("Name", p.Name))));
            }
            if (p.Comparison == Comparison.Null)
            {
                return(Subqueries.PropertyNotIn("ID",
                                                DetachedCriteria.For <ContentDetail>()
                                                .SetProjection(Projections.Property("EnclosingItem.ID"))
                                                .Add(Expression.Eq("Name", p.Name))));
            }

            return(Subqueries.PropertyIn("ID",
                                         DetachedCriteria.For <ContentDetail>()
                                         .SetProjection(Projections.Property("EnclosingItem.ID"))
                                         .Add(Expression.Eq("Name", p.Name))
                                         .Add(CreateExpression(ContentDetail.GetAssociatedPropertyName(p.Value), p.Value, p.Comparison))));
        }