Kentico Query Language

Sherry Collins asked on May 20, 2015 21:15

I am just learning the Kentico query language. I want to do two things.

  1. Get the PollID from the Polls_Poll table where the ActiveFlag = 1 ( i am going to add this field)
  2. When I get the PollID then pass that in another query to get the PostOpenTo Date for that pollid

Query 1 - I am getting error in my code as follows:

var whereQuery = PollInfoProvider.GetPolls() .Where("ActiveFlag", QueryOperator.Equals, "1") .OrderByDescending("PollID");

It gives me an error on the entire where clause - no overload for where takes 3 arguments. WhereEquals fails as well

Query 2 - Works OK but my question is can I pass wherequery as a parameter

DateTime PollClosed; var query = PollInfoProvider.GetPollInfo(wherequery); PollClosed = DateTime.Parse(query.PollOpenTo.ToShortDateString());

I can't test the 2nd query because I can't wherequery to work.

As always, thanks.

Recent Answers


Charles Matvchuk answered on May 20, 2015 21:32

Sherry, what type of field is ActiveFlag ? String, Int, Bool

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on May 20, 2015 21:37

Boolean

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 20, 2015 21:37

Sherry, I think your syntax is a little off, check this out:

var activePolls = PollInfoProvider.GetPolls("ActiveFlag = 1", "");
foreach (PollInfo pi in activePolls)
{
    DateTime pollClosedDate = pi.PollOpenTo;
}
0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on May 20, 2015 22:15

Thanks. I learned a lot today.

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 21, 2015 01:17

Glad we could all help out! Look me up if you need anything else, always open to helping others learn, and it's not fun doing it on your own.

0 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on May 22, 2015 17:30

I have another question, please. They decided not to add a flag to the table but to use the PollCodeName.

I can get the PollcodeName, but I am having trouble passing it in my

var PollCodeName = viewPoll.PollcodeName var activePolls = PollInfoProvider.GetPolls("PollCodeName = PollCodeName", "");

Is there a way I can pass PollcodeName by Value?

I would want it to evaluate to the following for this case. But basically I need to pass whatever poll is on the page. var activePolls = PollInfoProvider.GetPolls("PollCodeName = 'PortalSatisfaction'", "");

Thanks.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 22, 2015 18:25

Your query might change a bit then like so:

var allPolls = PollInfoProvider.GetPolls(); // get all the polls 
foreach (PollInfo pi in allPolls)
{
    switch (pi.PollCodeName.ToLower())
    {
        case ("poll.mycodename"):
            // do something here
            break;
        default:
            break;
    }
}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.