More in this section

Forums / Developing with Sitefinity / PollProvider issues

PollProvider issues

12 posts, 0 answered
  1. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    11 May 2010
    Link to this post
    I´m trying to implement a PollProvider that uses Telerik ORM with my own data model.

    I´m facing some issues with assumptions that the manager and the edit controls make, for example, the CreatePoll() function is called twice in the process of adding a new poll. This is strange and make a problem for me because generates two entities on the database, as I have to commit early because of locking issues.

    There is any documentation about the supposed behavior of the provider? What are the assumptions that I need to take in order to make it work? Anyone has an example of a full poll provider with other database scheme?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    12 May 2010
    Link to this post
    Hello Augusto Radtke,

    Could you please show us a sample of your CreatePoll code? Do you call the base method anywhere?

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    12 May 2010
    Link to this post
    Hello Radoslav,

    No, I don´t call it, because it´s abstract, it doesn´t exist at least when you derive from PollsProvider. The following code above:

    public override IPollItem CreatePoll()
    {
        using (var database = new Database()) {
            var poll = new Polls.Poll();
     
            poll.AddToDatabase(database.Scope);
     
            return poll;
        }
    }

    The Database class is a helper for the ORM, it starts a transaction if one is not already running and commit the changes, if any (using IsDirty) at the Dispose() of the using. Poll is my ORM mapped class.

    The problem seems to be on PollItemEdit control, it shouldn´t be calling the manager CreatePoll() twice, I believe.
  4. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    12 May 2010
    Link to this post
    Just to elaborate a little more, the first call comes from PollItemEdit.Insert(), with updatePoll as false, this is correct, then it creates one empty poll with one question and three answers, all empty.

    After that I hit the "Create this poll" button to save the poll and it calls again this time from else on PollItemEdit.Insert(), which calls PollItemEdit.CreatePoll(), because pollState is not null and it´s a postback.

    So far so good, but at PollItemEdit.CreatePoll() it check for the Poll property, which returns null, calling manager´s CreatePoll() again. The Poll property seems to check on this.poll, which I believe is null at this time, and on IsNewItem(), which should return false and because of that call manager´s GetPollById(), which is not happening.

    The IsNewItem() check if DataItemId is an empty guid, which at this point probably is. DataItemId is from ViewModeControl, which get a new guid from the QueryString. This is the point where I´m stuck right now.

    By the way, I found an typo error on CmsHttpRequest class, the property QueryString is written QueryStirng.
  5. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    13 May 2010
    Link to this post
    Isn't it clear? I will try to put a little more and simple...

    All controls are having the same behavior, it calls the provider to create the content even where they are not meant to and doesn't commit, when you save it (then it should create) it is saving for the second time.

    So the question remains
    "There is any documentation about the supposed behavior of the provider? What are the assumptions that I need to take in order to make it work? Anyone has an example of a full poll provider with other database scheme?"
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 May 2010
    Link to this post
    Hi Bruno Michels and Augusto Radtke,

    I understand what you are talking about. Would you like to set up a small runnable project with your custom provider added (not compiled code) and send it over to us. We will take a look at the provider and suggest any solutions.

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    14 May 2010
    Link to this post
    I´m working on it, on a proof-of-concept isolated project, will keep you updated as soon as possible.
  8. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    14 May 2010
    Link to this post
    Radoslav, I made a proof-of-concept project. The code is a little bit messy and some things seems weird decisions but it´s mostly because it´s off the context. In the actual project it makes sense. The objective is on QuayPollProvider.cs which is the original provider. It calls CreatePoll() twice. The project was created with Sitefinity 3.7.

    Here is the download link.
  9. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 May 2010
    Link to this post
    Hi Augusto Radtke,

    The issue is coming from the fact that on each method Create/Update in your provider you create new object scope and commit it at the end of the method. When the using finishes the database object is automatically disposed, thus committing whatever is in the transaction. Attached is sample code for OpenAccess enabled polls provider. Note this is very basic sample (most of the methods need implementation), but will be enough to give you an overview of how to do it.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    17 May 2010
    Link to this post
    Radoslav, I already tried that but I was stuck in a problem of the admin control not finding the question inside the poll because it wasn´t commited to the database. Your sample opened my eyes to the real problem behind it, the Questions enumerable of Poll class is a direct query to the database:

    public System.Collections.IList Questions
       {
           get
           {
               return ObjectScopeProvider.Scope.GetSqlQuery <QUAY.Social.PollQuestion>("QP_GetPollQuestions ?", "INTEGER poll").ExecuteEnumerable(Object.ID).Select(x => new Question(x)).ToList();
           }
       }

    That is not using the scope object cache. I saw on your sample that you use a tracked list and uses the ORM to populate this list, which probably use the current object cache. Can you send me the app.config of this sample to check how you mapped the questions to the poll?
  11. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    19 May 2010
    Link to this post
    Hello Augusto Radtke,

    I do not have app.config file. The provider was created by hand without using the open access tool to generate code. I my opinion it would be best if you store the poll id as a field on question. So the relationship of polls to questions would be one to many.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  12. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    19 May 2010
    Link to this post
    I managed to solve it, actually even doing by automatic ORM loading it couldn´t find the question if it wasn´t commited, the key solution was to add to the local poll question List<> after adding to the database, as in your example.
Register for webinar
12 posts, 0 answered