コード例 #1
0
        /// <summary>
        /// Gets the entities count.
        /// </summary>
        /// <param name="entityName">The entity name.</param>
        /// <param name="primaryKey">The primary key.</param>
        /// <param name="expression">The filter expression.</param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"><c>InvalidOperationException</c>.</exception>
        public override int GetEntitiesCount(string entityName, string primaryKey, FilterExpression expression)
        {
            Assert.ArgumentNotNullOrEmpty(entityName, "entityName");
            Assert.ArgumentNotNullOrEmpty(primaryKey, "primaryKey");

            string xml =
                CrmRemoteSettings.CrmService.Fetch(CountQuery.FormatWith(entityName, primaryKey,
                                                                         expression != null
                                                                  ? expression.ToFetchXml()
                                                                  : string.Empty));

            var resultXml  = XElement.Parse(xml);
            var resultNode = resultXml.Element("result");

            if (resultNode == null)
            {
                throw new InvalidOperationException(ResourceManager.Localize("CRM_AGR_QUERY_ERROR"));
            }
            var node = resultNode.Element("count");

            try
            {
                return(int.Parse(node.Value));
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(ResourceManager.Localize("CRM_AGR_QUERY_ERROR"), ex);
            }
        }
コード例 #2
0
        public virtual IActionResult Count([FromQuery] FilterQuery filterQuery)
        {
            var query  = new CountQuery <TModel>(filterQuery);
            var result = QueryDispatcher.Dispatch(query);

            return(Ok(result));
        }
コード例 #3
0
        /// <summary>
        /// Gets the entities count.
        /// </summary>
        /// <param name="logicalName">Name of the logical.</param>
        /// <param name="primaryKey">The primary key.</param>
        /// <param name="filteredFields">The filtered fields.</param>
        /// <param name="onlyActive">if set to <c>true</c> [only active].</param>
        /// <returns></returns>
        public override int GetEntitiesCount(string logicalName, string primaryKey, Dictionary <string, string> filteredFields, bool onlyActive)
        {
            const string CountQuery = "<fetch mapping='logical' aggregate='true'><entity name='{0}'><attribute name='{1}' aggregate='count' alias='count' />{2}</entity></fetch>";
            var          xml        = this.crmService.Fetch(CountQuery.FormatWith(logicalName, primaryKey, this.GetFilterExpression(filteredFields, onlyActive).ToFetchXml()));

            var resultXml  = XElement.Parse(xml);
            var resultNode = resultXml.Element("result");

            int returnValue = 0;

            if (resultNode == null)
            {
                return(returnValue);
            }

            var node = resultNode.Element("count");

            if (node == null)
            {
                return(returnValue);
            }

            int.TryParse(node.Value, out returnValue);

            return(returnValue);
        }
コード例 #4
0
        public virtual IActionResult Count(FindCriteria findCriteria)
        {
            var query  = new CountQuery <TModel>(findCriteria);
            var result = QueryDispatcher.Dispatch(query);

            return(Ok(result));
        }
コード例 #5
0
        public void CountQuery_ByType()
        {
            Prepare();
            CountQuery cq          = new CountQuery(typeof(Post));
            int        recordCount = (int)ActiveRecordMediator.ExecuteQuery(cq);

            Assert.AreEqual(3, recordCount);
        }
コード例 #6
0
ファイル: TransitReference.cs プロジェクト: belmirojr/dblog
        public override void Apply(CountQuery query)
        {
            if (!string.IsNullOrEmpty(SearchQuery))
            {
                query.Add(Expression.Like("Word", string.Format("%{0}%", SearchQuery)));
            }

            base.Apply(query);
        }
コード例 #7
0
        public override void Apply(CountQuery query)
        {
            if (DateStart != DateTime.MinValue)
            {
                query.Add(Expression.Ge("Created", DateStart));
            }

            base.Apply(query);
        }
コード例 #8
0
        public override void Apply(CountQuery query)
        {
            if (Type != TransitFeedType.Unknown)
            {
                query.Add(Expression.Eq("Type", Type.ToString()));
            }

            base.Apply(query);
        }
コード例 #9
0
        public override void Apply(CountQuery query)
        {
            if (AssociatedId != 0)
            {
                query.Add(Expression.Eq(string.Format("{0}.Id", Table), AssociatedId));
            }

            base.Apply(query);
        }
コード例 #10
0
ファイル: TransitFeedItem.cs プロジェクト: belmirojr/dblog
        public override void Apply(CountQuery query)
        {
            if (FeedId != 0)
            {
                query.Add(Expression.Eq("Feed.Id", FeedId));
            }

            base.Apply(query);
        }
コード例 #11
0
        public void CountQuery_PositionalParameters()
        {
            Prepare();
            object[]   parameters  = new object[] { "c" };
            CountQuery cq          = new CountQuery(typeof(Post), "Category = ?", parameters);
            int        recordCount = (int)ActiveRecordMediator.ExecuteQuery(cq);

            Assert.AreEqual(2, recordCount);
        }
コード例 #12
0
        public override void Apply(CountQuery query)
        {
            if (PostId != 0)
            {
                query.Add(Expression.Eq("Post.Id", PostId));
            }

            base.Apply(query);
        }
コード例 #13
0
ファイル: TransitImage.cs プロジェクト: belmirojr/dblog
        public override void Apply(CountQuery query)
        {
            if (mExcludeBlogImages)
            {
                query.Add(Expression.Sql("NOT EXISTS ( SELECT * FROM PostImage e WHERE e.Image_Id = this_.Image_Id )"));
                query.Add(Expression.Sql("NOT EXISTS ( SELECT * FROM Highlight h WHERE h.Image_Id = this_.Image_Id )"));
            }

            base.Apply(query);
        }
コード例 #14
0
        /// <summary>Builds a count query.</summary>
        /// <param name="filter">An optional filter.</param>
        /// <param name="token">Optional query token.</param>
        /// <returns>A count query.</returns>
        public static IQuery BuildCountQuery(FieldFilter filter = null, object token = null)
        {
            CountQuery countQuery = new CountQuery
            {
                Filter = filter,
                Token  = token
            };

            return(countQuery);
        }
コード例 #15
0
        public void CountQuery_DetachedCriteria()
        {
            Prepare();
            DetachedCriteria detachedCriteria = DetachedCriteria.For(typeof(Post));

            detachedCriteria.Add(Expression.Eq("Category", "c"));
            CountQuery cq          = new CountQuery(typeof(Post), detachedCriteria);
            int        recordCount = (int)ActiveRecordMediator.ExecuteQuery(cq);

            Assert.AreEqual(2, recordCount);
        }
コード例 #16
0
ファイル: TransitPost.cs プロジェクト: belmirojr/dblog
        public TransitPost(ISession session, DBlog.Data.Post o, bool hasaccess)
            : base(o.Id)
        {
            Title     = o.Title;
            Slug      = o.Slug;
            HasAccess = hasaccess;

            if (hasaccess)
            {
                mRawBody  = o.Body;
                Body      = Render(session, o.Body);
                BodyXHTML = RenderXHTML(session, o);
            }

            LoginId = o.Login.Id;

            if (o.PostImages != null && o.PostImages.Count > 0)
            {
                ImagesCount = o.PostImages.Count;

                if (hasaccess)
                {
                    ImageId = ((PostImage)TransitObject.GetRandomElement(o.PostImages)).Image.Id;
                }
            }

            // topics
            List <TransitTopic> topics = new List <TransitTopic>();

            if (o.PostTopics != null)
            {
                foreach (PostTopic postTopic in o.PostTopics)
                {
                    topics.Add(new TransitTopic(postTopic.Topic));
                }
            }
            mTopics = topics.ToArray();

            Created  = o.Created;
            Modified = o.Modified;

            CommentsCount = new CountQuery(session, typeof(PostComment), "PostComment")
                            .Add(Expression.Eq("Post.Id", o.Id))
                            .Execute <int>();

            Counter = TransitCounter.GetAssociatedCounter <Post, PostCounter>(
                session, o.Id);

            Publish = o.Publish;
            Display = o.Display;
            Sticky  = o.Sticky;
            Export  = o.Export;
        }
コード例 #17
0
 public override void Apply(CountQuery query)
 {
     if (SourceId != 0)
     {
         query.Add(Expression.Eq("SourceId", SourceId));
     }
     if (!string.IsNullOrEmpty(SourceType))
     {
         query.Add(Expression.Eq("SourceType", SourceType));
     }
     base.Apply(query);
 }
コード例 #18
0
        public void CountQuery_ByTypeAndCriteria()
        {
            Prepare();
            ICriterion[] criterionArray = new ICriterion[]
            {
                Expression.Eq("Category", "c")
            };
            CountQuery cq          = new CountQuery(typeof(Post), criterionArray);
            int        recordCount = (int)ActiveRecordMediator.ExecuteQuery(cq);

            Assert.AreEqual(2, recordCount);
        }
コード例 #19
0
ファイル: Misc.cs プロジェクト: dblock/dblog
        public void TestCountTopics()
        {
            TopicTest tt = new TopicTest();
            tt.Session = Session;
            tt.Create();

            int count = new CountQuery(Session, typeof(Topic), "Topic")
                .Add(Expression.Eq("Name", tt.Topic.Name))
                .Execute<int>();

            Assert.AreEqual(1, count);

            tt.Delete();
        }
コード例 #20
0
ファイル: TransitPostImage.cs プロジェクト: belmirojr/dblog
        public override void Apply(CountQuery query)
        {
            if (PostId != 0)
            {
                query.Add(Expression.Eq("Post.Id", PostId));
            }

            if (PreferredOnly)
            {
                throw new NotImplementedException();
            }

            base.Apply(query);
        }
コード例 #21
0
        public void TestCountTopics()
        {
            TopicTest tt = new TopicTest();

            tt.Session = Session;
            tt.Create();

            int count = new CountQuery(Session, typeof(Topic), "Topic")
                        .Add(Expression.Eq("Name", tt.Topic.Name))
                        .Execute <int>();

            Assert.AreEqual(1, count);

            tt.Delete();
        }
コード例 #22
0
ファイル: TransitPost.cs プロジェクト: belmirojr/dblog
        public override void Apply(CountQuery query)
        {
            if (TopicId != 0)
            {
                query.Add(Expression.Sql(string.Format("EXISTS ( SELECT * FROM PostTopic t WHERE t.Post_Id = this_.Post_Id AND t.Topic_Id = {0})",
                                                       TopicId)));
            }

            if (!string.IsNullOrEmpty(Query))
            {
                query.Add(Expression.Sql(string.Format("( FREETEXT (Title, '{0}') OR FREETEXT (Body, '{0}') )",
                                                       Renderer.SqlEncode(Query))));
            }

            if (DateStart != DateTime.MinValue)
            {
                query.Add(Expression.Ge("Created", DateStart));
            }

            if (DateEnd != DateTime.MaxValue)
            {
                query.Add(Expression.Le("Created", DateEnd));
            }

            if (PublishedOnly)
            {
                query.Add(Expression.Eq("Publish", true));
            }

            if (DisplayedOnly)
            {
                query.Add(Expression.Eq("Display", true));
            }

            base.Apply(query);
        }
コード例 #23
0
ファイル: WebServices.Blog.cs プロジェクト: dblock/dblog
 public int GetBrowsersCount(string ticket, WebServiceQueryOptions options)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CountQuery query = new CountQuery(session, typeof(DBlog.Data.Browser), "Browser");
         if (options != null) options.Apply(query);
         return query.Execute<int>();
     }
 }
コード例 #24
0
ファイル: WebServices.Blog.cs プロジェクト: dblock/dblog
 public int GetLoginsCount(string ticket, WebServiceQueryOptions options)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CheckAdministrator(session, ticket);
         CountQuery query = new CountQuery(session, typeof(DBlog.Data.Login), "Login");
         if (options != null) options.Apply(query);
         return query.Execute<int>();
     }
 }
コード例 #25
0
ファイル: TransitPostLogin.cs プロジェクト: dblock/dblog
        public override void Apply(CountQuery query)
        {
            if (PostId != 0)
            {
                query.Add(Expression.Eq("Post.Id", PostId));
            }

            base.Apply(query);
        }
コード例 #26
0
        public override void Apply(CountQuery query)
        {
            if (AssociatedId != 0)
            {
                query.Add(Expression.Eq(string.Format("{0}.Id", Table), AssociatedId));
            }

            base.Apply(query);
        }
コード例 #27
0
ファイル: TransitFeedItem.cs プロジェクト: dblock/dblog
        public override void Apply(CountQuery query)
        {
            if (FeedId != 0)
            {
                query.Add(Expression.Eq("Feed.Id", FeedId));
            }

            base.Apply(query);
        }
コード例 #28
0
ファイル: TransitPostImage.cs プロジェクト: dblock/dblog
        public override void Apply(CountQuery query)
        {
            if (PostId != 0)
            {
                query.Add(Expression.Eq("Post.Id", PostId));
            }

            if (PreferredOnly)
            {
                throw new NotImplementedException();
            }

            base.Apply(query);
        }
コード例 #29
0
        /// <summary>
        /// Returns the number of records of the specified
        /// type in the database
        /// </summary>
        /// <example>
        /// <code>
        /// [ActiveRecord]
        /// public class User : ActiveRecordBase
        /// {
        ///   ...
        ///
        ///   public static int CountUsersLocked()
        ///   {
        ///     return Count(typeof(User), "IsLocked = ?", true);
        ///   }
        /// }
        /// </code>
        /// </example>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="filter">A sql where string i.e. Person=? and DOB &gt; ?</param>
        /// <param name="args">Positional parameters for the filter string</param>
        /// <returns>The count result</returns>
        public static int Count(Type targetType, string filter, params object[] args)
        {
            CountQuery query = new CountQuery(targetType, filter, args);

            return((int)ExecuteQuery(query));
        }
コード例 #30
0
ファイル: TransitReferrerHost.cs プロジェクト: dblock/dblog
        public override void Apply(CountQuery query)
        {
            if (DateStart != DateTime.MinValue)
            {
                query.Add(Expression.Ge("Created", DateStart));
            }

            base.Apply(query);
        }
コード例 #31
0
ファイル: TransitReference.cs プロジェクト: dblock/dblog
        public override void Apply(CountQuery query)
        {
            if (!string.IsNullOrEmpty(SearchQuery))
            {
                query.Add(Expression.Like("Word", string.Format("%{0}%", SearchQuery)));
            }

            base.Apply(query);
        }
コード例 #32
0
ファイル: TransitImage.cs プロジェクト: dblock/dblog
        public override void Apply(CountQuery query)
        {
            if (mExcludeBlogImages)
            {
                query.Add(Expression.Sql("NOT EXISTS ( SELECT * FROM PostImage e WHERE e.Image_Id = this_.Image_Id )"));
                query.Add(Expression.Sql("NOT EXISTS ( SELECT * FROM Highlight h WHERE h.Image_Id = this_.Image_Id )"));
            }

            base.Apply(query);
        }
コード例 #33
0
ファイル: WebServices.Blog.cs プロジェクト: dblock/dblog
 public int GetPostsCount(string ticket, TransitPostQueryOptions options)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CountQuery query = new CountQuery(session, typeof(DBlog.Data.Post), "Post");
         if (options != null)
         {
             options.Apply(query);
         }
         if (options != null) options.Apply(query);
         return query.Execute<int>();
     }
 }
コード例 #34
0
ファイル: WebServices.Blog.cs プロジェクト: dblock/dblog
 public int SearchReferencesCount(string ticket, TransitReferenceQueryOptions options)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CountQuery query = new CountQuery(session, typeof(DBlog.Data.Reference), "Reference");
         if (options != null)
         {
             options.Apply(query);
         }
         return query.Execute<int>();
     }
 }
コード例 #35
0
        /// <summary>
        /// Returns the number of records of the specified
        /// type in the database
        /// </summary>
        /// <param name="targetType">The target type.</param>
        /// <param name="detachedCriteria">The criteria expression</param>
        /// <returns>The count result</returns>
        public static int Count(Type targetType, DetachedCriteria detachedCriteria)
        {
            CountQuery query = new CountQuery(targetType, detachedCriteria);

            return((int)ExecuteQuery(query));
        }
コード例 #36
0
ファイル: Schema.cs プロジェクト: CodenameLiam/Lactalis
        /// <summary>
        /// Adds single, multiple and connection queries to query
        /// </summary>
        /// <typeparam name="TModelType">The GraphQL type for returning data</typeparam>
        /// <typeparam name="TModel">The EF model type for querying the DB</typeparam>
        /// <param name="name">The name of the entity</param>
        public void AddModelQueryField <TModelType, TModel>(string name)
            where TModelType : ObjectGraphType <TModel>
            where TModel : class, IOwnerAbstractModel, new()
        {
            AddQueryField(
                $"{name}s",
                QueryHelpers.CreateResolveFunction <TModel>(),
                typeof(TModelType)).Description = $"Query for fetching multiple {name}s";

            AddSingleField(
                name: name,
                resolve: QueryHelpers.CreateResolveFunction <TModel>(),
                graphType: typeof(TModelType)).Description = $"Query for fetching a single {name}";

            AddQueryConnectionField(
                $"{name}sConnection",
                QueryHelpers.CreateResolveFunction <TModel>(),
                typeof(TModelType));

            FieldAsync <NumberObjectType>(
                $"count{name}s",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <ListGraphType <IdGraphType> > {
                Name = "ids"
            },
                    new QueryArgument <ListGraphType <WhereExpressionGraph> >
            {
                Name        = "where",
                Description = WhereDesc
            }
                    ),
                resolve: CountQuery.CreateCountQuery <TModel>(),
                description: "Counts the number of models according to a given set of conditions"
                );

            AddQueryField(
                $"{name}sConditional",
                ConditionalQuery.CreateConditionalQuery <TModel>(),
                typeof(TModelType),
                new QueryArguments(
                    new QueryArgument <ListGraphType <ListGraphType <WhereExpressionGraph> > >
            {
                Name        = "conditions",
                Description = ConditionalWhereDesc
            }
                    )
                );

            FieldAsync <NumberObjectType>(
                $"count{name}sConditional",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <ListGraphType <IdGraphType> > {
                Name = "ids"
            },
                    new QueryArgument <ListGraphType <ListGraphType <WhereExpressionGraph> > >
            {
                Name        = "conditions",
                Description = ConditionalWhereDesc
            }
                    ),
                resolve: CountQuery.CreateConditionalCountQuery <TModel>(),
                description: "Counts the number of models according to a given set of conditions. This query can " +
                "perform both AND and OR conditions"
                );
        }
コード例 #37
0
ファイル: TransitPost.cs プロジェクト: dblock/dblog
        public TransitPost(ISession session, DBlog.Data.Post o, bool hasaccess)
            : base(o.Id)
        {
            Title = o.Title;
            Slug = o.Slug;
            HasAccess = hasaccess;

            if (hasaccess)
            {
                mRawBody = o.Body;
                Body = Render(session, o.Body);
                BodyXHTML = RenderXHTML(session, o);
            }

            LoginId = o.Login.Id;

            if (o.PostImages != null && o.PostImages.Count > 0)
            {
                ImagesCount = o.PostImages.Count;

                if (hasaccess)
                {
                    ImageId = ((PostImage)TransitObject.GetRandomElement(o.PostImages)).Image.Id;
                }
            }

            // topics
            List<TransitTopic> topics = new List<TransitTopic>();
            if (o.PostTopics != null)
            {
                foreach (PostTopic postTopic in o.PostTopics)
                {
                    topics.Add(new TransitTopic(postTopic.Topic));
                }
            }
            mTopics = topics.ToArray();

            Created = o.Created;
            Modified = o.Modified;

            CommentsCount = new CountQuery(session, typeof(PostComment), "PostComment")
                .Add(Expression.Eq("Post.Id", o.Id))
                .Execute<int>();

            Counter = TransitCounter.GetAssociatedCounter<Post, PostCounter>(
                session, o.Id);

            Publish = o.Publish;
            Display = o.Display;
            Sticky = o.Sticky;
            Export = o.Export;
        }
コード例 #38
0
        /// <summary>
        /// Returns the number of records of the specified
        /// type in the database
        /// </summary>
        /// <example>
        /// <code>
        /// [ActiveRecord]
        /// public class User : ActiveRecordBase
        /// {
        ///   ...
        ///
        ///   public static int CountUsers()
        ///   {
        ///     return Count(typeof(User));
        ///   }
        /// }
        /// </code>
        /// </example>
        /// <param name="targetType">Type of the target.</param>
        /// <returns>The count result</returns>
        protected internal static int Count(Type targetType)
        {
            CountQuery query = new CountQuery(targetType);

            return((int)ExecuteQuery(query));
        }
コード例 #39
0
ファイル: TransitPost.cs プロジェクト: dblock/dblog
        public override void Apply(CountQuery query)
        {
            if (TopicId != 0)
            {
                query.Add(Expression.Sql(string.Format("EXISTS ( SELECT * FROM PostTopic t WHERE t.Post_Id = this_.Post_Id AND t.Topic_Id = {0})",
                    TopicId)));
            }

            if (! string.IsNullOrEmpty(Query))
            {
                query.Add(Expression.Sql(string.Format("( FREETEXT (Title, '{0}') OR FREETEXT (Body, '{0}') )",
                    Renderer.SqlEncode(Query))));
            }

            if (DateStart != DateTime.MinValue)
            {
                query.Add(Expression.Ge("Created", DateStart));
            }

            if (DateEnd != DateTime.MaxValue)
            {
                query.Add(Expression.Le("Created", DateEnd));
            }

            if (PublishedOnly)
            {
                query.Add(Expression.Eq("Publish", true));
            }

            if (DisplayedOnly)
            {
                query.Add(Expression.Eq("Display", true));
            }

            base.Apply(query);
        }
コード例 #40
0
        /// <summary>
        /// Returns the number of records of the specified
        /// type in the database
        /// </summary>
        /// <param name="targetType">The target type.</param>
        /// <param name="criteria">The criteria expression</param>
        /// <returns>The count result</returns>
        public static int Count(Type targetType, params ICriterion[] criteria)
        {
            CountQuery query = new CountQuery(targetType, criteria);

            return((int)ExecuteQuery(query));
        }
コード例 #41
0
ファイル: WebServices.Blog.cs プロジェクト: dblock/dblog
 public int GetFeedsCount(string ticket, TransitFeedQueryOptions options)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CountQuery q = new CountQuery(session, typeof(DBlog.Data.Feed), "Feed");
         if (options != null)
         {
             options.Apply(q);
         }
         return q.Execute<int>();
     }
 }
コード例 #42
0
ファイル: TransitFeed.cs プロジェクト: dblock/dblog
        public override void Apply(CountQuery query)
        {
            if (Type != TransitFeedType.Unknown)
            {
                query.Add(Expression.Eq("Type", Type.ToString()));
            }

            base.Apply(query);
        }
コード例 #43
0
ファイル: TransitPermalink.cs プロジェクト: dblock/dblog
 public override void Apply(CountQuery query)
 {
     if (SourceId != 0) query.Add(Expression.Eq("SourceId", SourceId));
     if (!string.IsNullOrEmpty(SourceType)) query.Add(Expression.Eq("SourceType", SourceType));
     base.Apply(query);
 }