DataServiceKey attribute and ADO.NET dataservice

4 posts, 1 answers
  1. Henk
    Henk avatar
    113 posts
    Member since:
    Apr 2006

    Posted 02 Nov 2009 Link to this post

    Hello,

    I tried to make an ADO.NET dataservice using the OA WCF wizard.
    I had a problem using the ADO.NET dataservice because there are no DataServiceKey attributes added to the OA classes.
    Is it possible to automatically add a DataServiceKey attribute to each class based on the primary key fields of the table?
  2. Answer
    Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 03 Nov 2009 Link to this post

    Hi Henk Boen,

    You can edit the template that OpenAccess uses for class generation. The directory where the templates reside is <OpenAccess install path>\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\class. If you are using partial classes open the partialdesignerdefault.vm file, otherwise - the default.vm file. In both cases, the file contains a line similar to this:
    ...
    public partial class $className
    ...
    What you should do is to add the DataServiceKey attribute above as follows:
    ...
    [DataServiceKey#if($singleField)("$(pkField)")#end]
    public partial class $className
    ...
    Note that changing the templates reflects all newly generated classes. If you do not need the DataServiceKey attribute anymore, please revert the changes.

    Greetings,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Sam
    Sam avatar
    11 posts
    Member since:
    Oct 2009

    Posted 07 Nov 2009 Link to this post

    hi Alexander,
    i faced same issue and i have one issue with your solution 
    pkField return the field Name while i need the pk Property Name 
    how can i return it instead on the Field name? 

    best regards,
    Sam

  5. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 11 Nov 2009 Link to this post

    Hello Sam,

    We are aware of this problem. The functionality is implemented and it will be part of our next internal build. With the next build you will be able to modify the template as follows:
    [DataServiceKey#if($multipleField)(new string[]{"$(pkProperties)"})#end#if($singleField)("$(pkProperty)")#end]
    As you can see above, the template will be able to generate the correct DataServiceKey for both single identity and multiple identity.

    Sincerely yours,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top