This is a migrated thread and some comments may be shown as answers.

IdentityField is being ignored for one-way PK?

8 Answers 119 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nathan J Pledger
Top achievements
Rank 2
Nathan J Pledger asked on 21 Dec 2008, 01:04 PM

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.

8 Answers, 1 is accepted

Sort by
0
Nathan J Pledger
Top achievements
Rank 2
answered on 22 Dec 2008, 10:12 AM
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.
0
Alexander
Telerik team
answered on 22 Dec 2008, 10:14 AM
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.
0
Nathan J Pledger
Top achievements
Rank 2
answered on 22 Dec 2008, 10:28 AM
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!

0
Alexander
Telerik team
answered on 23 Dec 2008, 03:25 PM
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.
0
Nathan J Pledger
Top achievements
Rank 2
answered on 23 Dec 2008, 03:35 PM
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.

0
Accepted
Dimitar Kapitanov
Telerik team
answered on 23 Dec 2008, 05:08 PM
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.
0
Nathan J Pledger
Top achievements
Rank 2
answered on 23 Dec 2008, 06:17 PM
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!
0
Dimitar Kapitanov
Telerik team
answered on 27 Dec 2008, 08:44 AM
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.
Tags
General Discussions
Asked by
Nathan J Pledger
Top achievements
Rank 2
Answers by
Nathan J Pledger
Top achievements
Rank 2
Alexander
Telerik team
Dimitar Kapitanov
Telerik team
Share this question
or