IdentityField is being ignored for one-way PK?

9 posts, 1 answers
  1. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 21 Dec 2008 Link to this post


    Hi,

    I am struggling to get a rather simple class/data mapping working out and am not finding a resolution in the various documentation sources.

    I have a class:

        [Telerik.OpenAccess.Persistent(IdentityField = "Id")]  
        public partial class Site  
        {  
            private Guid _id; // pk   
            private string _baseUrl;  
     
            private string _siteName;  
     
            private string _theme;  
     
        } 

    ... with the "other side" of the partial class looking like:

        public partial class Site : ISite  
        {  
            //The 'no-args' constructor required by OpenAccess.   
            public Site()   
            {  
            }  
     
            [Telerik.OpenAccess.FieldAlias("id")]  
            public Guid Id  
            {  
                get { return _id; }  
                set { this._id = value; }  
            }  
     
            [Telerik.OpenAccess.FieldAlias("baseUrl")]  
            public string BaseUrl  
            {  
                get { return _baseUrl; }  
                set { this._baseUrl = value; }  
            }  
     
            [Telerik.OpenAccess.FieldAlias("siteName")]  
            public string SiteName  
            {  
                get { return _siteName; }  
                set { this._siteName = value; }  
            }  
     
            [Telerik.OpenAccess.FieldAlias("theme")]  
            public string Theme  
            {  
                get { return _theme; }  
                set { this._theme = value; }  
            }  
     
     
        } 

    All very simple.

    And yet I get the compile error:

    Error 102 OpenAccess Error: The IdentityField specified is not declared on this class. [class=ProgramX.Xsist.Core.Data.Site] [field=Id] D:\dev_px\Xsist\ProgramX.Xsist\Site.cs 10 

    Do I not specify the Persistant attribute, which should define a one-way primary key? Your documentation at http://www.telerik.com/help/openaccess-orm/object-identity-single-field.html also does not tell me how to get to that window. And despite searching for it, I can't find it. I'm using the Express version, until I decide to upgrade my sub, depending on whether I get on with it.
  2. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 22 Dec 2008 Link to this post

    Ok, I'll reply to myself for the benefit of Google.
    Turns out that the:

    [Telerik.OpenAccess.Persistent(IdentityField = "_id")] 

    attribute refers to the private class member. (ie. "_id" instead of the DB field name)

    Ditto for the field level attributes:

    [Telerik.OpenAccess.FieldAlias("_id")] 

    Guess I'll have to tweak my templates.

    All looks very exciting, though. Hav renewed by sub and upgraded to Premium version.
  3. DevCraft banner
  4. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 22 Dec 2008 Link to this post

    Hi Nathan,

    To specify the identity field you should use the private field "_id" instead of the "Id" public property.

    All the best,
    Alexander
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 22 Dec 2008 Link to this post

    Thanks Alexander.

    My templates are coming out with my preferred coding style of "_id" instead of "id" for my private members.

    But how do I get the reverse engineering to reflect the same scheme? At the moment I am having to go into the Advanced Tree mode in Reverse Engineering and manually tweaking each member - a pain, you must agree!

  6. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 23 Dec 2008 Link to this post

    Hi Nathan,

    This is possible by changing the templates in your OpenAccess installation path. To modify the template for the generation of the private fields you have to open the "<path>\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\fields\field\declaration\default.vm" file in a text editor and put the '_' symbol exactly before the "$fieldName" string.
    As you can see the templates are fully customizable and you have a lot of freedom but be careful.
    You could also find the full reference about reverse mapping templates here .

    Kind regards,
    Alexander
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 23 Dec 2008 Link to this post

    Thanks, Alexander.

    I understand that part. But what about the reverseMapping.config and App.config mapping files? How can I get these to also use the "_" notation? Even editing the field anmes in the advanced tree view reverse mapping dialogue has no effect - it just changes the fieldnames back.

  8. Answer
    Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 23 Dec 2008 Link to this post

    Hi Nathan J Pledger,
    It looks like we have issue with our wizard dialog. We will evaluate the fault behavior in details and schedule it for fixing. I will contact you asap when we have a clear view of the situation. Your Telerik points were updated.


    Best wishes,
    Dimitar Kapitanov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 23 Dec 2008 Link to this post

    Hi Alexander,

    Thanks a lot for looking into it, and for the points.

    Wish I'd have found it before I upgraded my sub now!
  10. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 27 Dec 2008 Link to this post

    Hi Nathan J Pledger,
    Thank you for your appreciation and understanding. If you have any other suggestions or problems regarding the use of OpenAccess, do not hesitate to share them with us.

    All the best,
    Dimitar Kapitanov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
DevCraft banner