Question

RowCount

 

 Hi,

          I made a service which takes string input and return record if it found if it does not find then it return -1 . I want if record found then it return rowcount ?

how i can return count(*)

thanks

Like 0

Like

4 comments

Hello Muhammad!



I`m glad to answer to your question. In this case you should modify the service that you have written before. The key to understand how to get amount of rows in table is to know how to use entity schema query. You can get the desired information by executing one more query regarding to results of first query (string is found or not). To get amount of rows that select returned use the "RowCount" property of "Select" class. 

ESQ: https://academy.bpmonline.com/documents/technic-sdk/7-13/retrieving-inf….

Alex_Tim,

here is my code please suggest me how i can use it

namespace Terrasoft.Configuration.UsrCustomConfigurationService

{

    using System;

    using System.ServiceModel;

    using System.ServiceModel.Web;

    using System.ServiceModel.Activation;

    using Terrasoft.Core;

    using Terrasoft.Web.Common;

    using Terrasoft.Core.Entities; 

    [ServiceContract]

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

    public class UsrCustomConfigurationService: BaseService

    {

        // Link to the UserConnection instance required to access the database.

        private SystemUserConnection _systemUserConnection;

        private SystemUserConnection SystemUserConnection {

            get {

                return _systemUserConnection ?? (_systemUserConnection = (SystemUserConnection)AppConnection.SystemUserConnection);

            }

        }

        

        [OperationContract]

        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,

        ResponseFormat = WebMessageFormat.Json)]

        public string GetPlannedIssueByName(string Name){

            // The default result.

            var result = "";

            // An EntitySchemaQuery instance that accesses the Contact table of the database.

            var esq = new EntitySchemaQuery(SystemUserConnection.EntitySchemaManager, "UsrIssuesDetail");

            // Adding columns to the query.

            var colId = esq.AddColumn("UsrIssueStatus.Name");

            //var colName = esq.AddColumn("Name");

            // Filter the query data.

            var esqFilter = esq.CreateFilterWithParameters(FilterComparisonType.Equal, "UsrIssueStatus.Name", Name);

            esq.Filters.Add(esqFilter);

            // Get the result of the query.

            var entities = esq.GetEntityCollection(SystemUserConnection);

            // If the data is received.

            if (entities.Count > 0)

            {

                // Return the value of the "Id" column of the first record of the query result.

                result = entities[0].GetColumnValue(colId.Name).ToString();

                // You can also use this option:

                // result = entities [0]. GetTypedColumnValue <string> (colId.Name);

            }

            else

            {

                result = "-1";

            }

            // Return the result.

            return result;

        }

    }

}

 

Hello Muhammad,



I have made some changes in your code and now it should returns amount of rows in entire table if your string is found.

 

Best regards,

Alex

  [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
        ResponseFormat = WebMessageFormat.Json)]
        public string GetPlannedIssueByName(string Name){
            // The default result.
            var result = "";
            // An EntitySchemaQuery instance that accesses the Contact table of the database.
            var esq = new EntitySchemaQuery(SystemUserConnection.EntitySchemaManager, "UsrIssuesDetail");
            // Adding columns to the query.
            var colId = esq.AddColumn("UsrIssueStatus.Name");
            //var colName = esq.AddColumn("Name");
            // Filter the query data.
            var esqFilter = esq.CreateFilterWithParameters(FilterComparisonType.Equal, "UsrIssueStatus.Name", Name);
            esq.Filters.Add(esqFilter);
            // Get the result of the query.
            var entities = esq.GetEntityCollection(SystemUserConnection);
            // If the data is received.
            if (entities.Count &gt; 0)
            {
				var esq2 = new EntitySchemaQuery(SystemUserConnection.EntitySchemaManager, "UsrIssuesDetail");
				var colId = esq2.AddColumn("UsrIssueStatus.Name");
				var amountOfAllRows = esq2.GetEntityCollection(SystemUserConnection).RowCount;
 
				result = amountOfAllRows.ToString();
 
                // Return the value of the "Id" column of the first record of the query result.
                //result = entities[0].GetColumnValue(colId.Name).ToString();
                // You can also use this option:
                // result = entities [0]. GetTypedColumnValue &lt;string&gt; (colId.Name);
            }
            else
            {
                result = "-1";
            }
            // Return the result.
            return result;
        }
    }

 

thanks dear

Show all comments