Editing a grid using OpenAccess datasource

11 posts, 1 answers
  1. MWM
    MWM avatar
    64 posts
    Member since:
    Jul 2007

    Posted 07 Dec 2008 Link to this post

    Not sure if this error is coming from OA or the grid itself so please bear with me.  I have an OA datasource dropped onto an ASPX page.  The source is a simple table with two fields, a PK and a description.  I set to auto-gen fields in RadGrid and allowing auto-insertions, updates and deletes.  I'm sure there's a simple fix to this, but I don't know it.  Thanks for any assistance!

    Changes are not possible if the primary key fields are not visible.
    Please specify the id and version fields in the persistent attribute.
    [Telerik.OpenAccess.Persistent(IdentityFied="id", VersionField="version"]

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Telerik.OpenAccess.Exceptions.UnsupportedException: Changes are not possible if the primary key fields are not visible.
    Please specify the id and version fields in the persistent attribute.
    [Telerik.OpenAccess.Persistent(IdentityFied="id", VersionField="version"]

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [UnsupportedException: Changes are not possible if the primary key fields are not visible.
    Please specify the id and version fields in the persistent attribute.
    [Telerik.OpenAccess.Persistent(IdentityFied="id", VersionField="version"]]
       Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.CreateObjectId(IDictionary keys, String& oldVersion) +100
       Telerik.OpenAccess.RT.DataSource.OpenAccessDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +141
       System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
       Telerik.Web.UI.GridTableView.PerformUpdate(GridEditableItem editedItem, Boolean suppressRebind) +353
       Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +1997
       Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +191
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       Telerik.Web.UI.GridEditFormItem.OnBubbleEvent(Object source, EventArgs e) +439
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
    
  2. Answer
    Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 08 Dec 2008 Link to this post

    Hi MWM,
    If you are using visible id fields (pls. check the Persistent attribute) this error is because of an older OpenAccess version.
    The dataKeyNames property of the grid is not set correctly. With the latest OpenAccess version please rebind the datasource to the grid and it should work.

    Regards,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
  4. Markus Ruf
    Markus Ruf avatar
    29 posts
    Member since:
    Dec 2008

    Posted 22 Jan 2009 Link to this post

    Hi Jan

    I have the same problem as above discribed.
    I have the Q3 2008 products of OA and RadControls. Actuality should not be the problem.

    my code:
    ------------ OA section

    //Generated by Telerik OpenAccess

     

    [Telerik.OpenAccess.Persistent(IdentityField = "kId")]
    public partial class Kunde
    {

     

      private int kId; // pk
     
    private bool kAktiv;
      private DateTime? kAktivBis;
      ....
    ------------

    ... as seen in the demos, i have to use advanced-databinding ...
    ------------ ASP.NET Section
    ...
      protected void Page_Load(object sender, EventArgs e)
      {

      

    if (!Page.IsPostBack)
      {
       
    RadGridAccounts.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(RadGridAccounts_NeedDataSource);
      }
    }

      protected
    void RadGridAccounts_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

     

      {
       

    RadGridAccounts.DataSourceID = "OpenAccessDataSource1";
     
    }
    }

     

     

     

    ------------

    The id field is visible, but there is no version field in the table.
    Any ideas?

    TIA!
    Markus

  5. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 22 Jan 2009 Link to this post

    Hi Markus Ruf,
    The problem with the missing version field is that the concurrency control will not work.

    Is it a big problem to add it?

    Greetings,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Markus Ruf
    Markus Ruf avatar
    29 posts
    Member since:
    Dec 2008

    Posted 23 Jan 2009 Link to this post

    Hi Jan

    Thanks for your reply.

    I added an Version-field into the table and reverse mapped it again.

    The new field "kVersion" was added into app.config and reversemapping.config, but neither in Kunde.cs nor Kunde.Telerik.OpenAcess.cs.
    I can compile this, but the runtime-error when i try the update button of the grid remains the same.

    If i manually add the VersionField [Telerik.OpenAccess.Persistent(IdentityField="kId", VersionField="kVersion")] in Kunde.Telerik.OpenAccess.cs , i can't compile anymore:

    Fehler 119 OpenAccess Error: The VersionField specified is not declared on this class. [class=DAL.Kunde] [field=kVersion] ...\DAL\Kunde.cs 9 

    Any hints?

    Regards
    Markus
  7. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 23 Jan 2009 Link to this post

    Hello Markus Ruf,
    Did you regenerate the respective class?

    Can you send me your reversemapping.config with the info which node has the problem?

    Sincerely yours,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Markus Ruf
    Markus Ruf avatar
    29 posts
    Member since:
    Dec 2008

    Posted 26 Jan 2009 Link to this post

    Hi Jan

    Yes, I regenerated this class.
    Here is the reversemapping.config. I removed the classGenerator Info of the other, unused tables.

     ------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <openaccess>
        <classGenerator defaultPackageName="DAL">
            <table name="'Kunde'" type="1" locked="False">
                <column name="K_Id" isPk="True" isAutoInc="True" adoType="4" sqlType="int" length="0" isNull="False" />
                <column name="K_Version" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="False" />
                <column name="K_AktivVon" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" />
                <column name="K_AktivBis" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" />
                <column name="K_Aktiv" isPk="False" isAutoInc="False" adoType="-7" sqlType="bit" length="0" isNull="False" />
                <column name="K_System" isPk="False" isAutoInc="False" adoType="-7" sqlType="bit" length="0" isNull="False" />
                <column name="K_Lieferant" isPk="False" isAutoInc="False" adoType="-7" sqlType="bit" length="0" isNull="False" />
                <column name="K_Demo" isPk="False" isAutoInc="False" adoType="-7" sqlType="bit" length="0" isNull="False" />
                <column name="K_MutDatum" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="False" />
                <column name="K_B_Id" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" />
                <class name="Kunde" check="-1573426966" generated="True">
                    <field name="kId" type="1" isPK="True" isAutoInc="True" column="K_Id" valueType="System.Int32" />
                    <field name="kAktiv" type="1" isPK="False" column="K_Aktiv" valueType="System.Boolean" />
                    <field name="kAktivBis" type="1" isPK="False" column="K_AktivBis" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" />
                    <field name="kAktivVon" type="1" isPK="False" column="K_AktivVon" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" />
                    <field name="kBId" type="1" isPK="False" column="K_B_Id" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" />
                    <field name="kDemo" type="1" isPK="False" column="K_Demo" valueType="System.Boolean" />
                    <field name="kLieferant" type="1" isPK="False" column="K_Lieferant" valueType="System.Boolean" />
                    <field name="kMutDatum" type="1" isPK="False" column="K_MutDatum" valueType="System.DateTime" />
                    <field name="kSystem" type="1" isPK="False" column="K_System" valueType="System.Boolean" />
                    <field name="kVersion" type="1" isPK="False" isVersion="True" column="K_Version" valueType="System.Int32" />
                </class>
            </table>
        </classGenerator>
        <options>
            <sourcegeneration partial="True" />
            <allSchemata>
                <schemata name="(default)" />
            </allSchemata>
            <usedSchemata>
                <schemata name="(default)" />
            </usedSchemata>
            <mapping>
                <identity explicitIDClass="False" />
            </mapping>
        </options>
    </openaccess>

     ------------------

    The new field I have inserted for the version is the "K_Version" field.
    This version field don't appear in the class files, as mentioned before.

    Kind regards,
    Markus

  9. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 28 Jan 2009 Link to this post

    Hi Markus Ruf,
    We have found the problem. It has to do with the version settings. After a first look I think the complete setting is not working. As workaround pls. remove the version checkbox check and generate all. Then open the forward mapping wizard and set the field as version field again.

    The problem is, that you have to make it whenever you regenerate this source.

    Best wishes,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. Markus Ruf
    Markus Ruf avatar
    29 posts
    Member since:
    Dec 2008

    Posted 30 Jan 2009 Link to this post

    Hi Jan

    Thanks for your answer.
    Unfortunatly the workaround didn't work. The same error is still there [visible in a Javascript-Error window].

    I have no time to follow this thread here any longer. It was not the way I wanted to implement the whole thing. It was just my first approach into RADControls and OA-ORM, and to follow the steps I saw on a demo Telerik-Video, and see what should be possible. (Sorry, i'm not satisfied with the result.)
    I'll try now another approach. No more autogenerated columns and autogenerated update (within the grid). I have to verify the datas before writing to the db anyway. My other test with manualy update the OA-generated class worked (so far), that's the way i wanna go now.

    Thanks and kind regards,
    Markus
  11. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 06 Nov 2012 Link to this post

    Hi All,

    I got this error using a new "RadControls Web Application" project. I could add a record, but could not query; the error above.

    When I added a standard WebApplication project it all works fine. No clue why, all was the same (refs) and querying code. I Tried console also for testing and also no problems, but a "RadControls Web Application" project would just not go.

    Erik
  12. Ady
    Admin
    Ady avatar
    589 posts

    Posted 09 Nov 2012 Link to this post

    Hello Erik,

     Can you provide some more details of the error. What are you trying to achieve and what is the exception you get? Are you using the the 'Classic' product where your mapping is in the app.config file or are you using a domain model (.rlinq file)?

    All the best,
    Ady
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Back to Top
DevCraft banner