keeping relational id properties

6 posts, 0 answers
  1. RICHARD FRIEND
    RICHARD FRIEND avatar
    16 posts
    Member since:
    Nov 2008

    Posted 02 Jul 2009 Link to this post

    Hi

    I have an entity of Company that has a property of ParentCompanyId.

    When i reverse map this and add the relationship i get

    Company.ParentCompany

    but i would like to keep

    Company.ParentCompanyId

    to save me having to load the company object just to get id, is this possible?
  2. RICHARD FRIEND
    RICHARD FRIEND avatar
    16 posts
    Member since:
    Nov 2008

    Posted 02 Jul 2009 Link to this post

    Also

    I have a RowVersion(int) in all my tables, i wish to use this as my concurrency version field, however i also want to display this on my app, openaccess removes the property from my class when i set it to version, any way to prevent this ?
  3. DevCraft banner
  4. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 03 Jul 2009 Link to this post

    Hello Richard,

    Yes, this is possible. Just delete the reference from the Reverse mapping wizard, the ID property will be generated instead. Note that if you have already generated a partial class for this table, its relevant .cs file will not be changed in order to keep any changes you might have made there. You can find the new code in a commented block at the bottom of the .Telerik.OpenAccess.cs file and just copy it to the actual .cs file.

    Regarding the second question, I do not think this should be done. When you set the field to 'version', it is marked to be handled internally and if you expose it in the class, this may lead to insert / update problems. We already had a similar issue with a discriminator column in this thread. Read was fine, but the Inserts were failing.

    Greetings,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. RICHARD FRIEND
    RICHARD FRIEND avatar
    16 posts
    Member since:
    Nov 2008

    Posted 06 Jul 2009 Link to this post

    Hi

    In regards to my second question, i know i shouldnt be mapping this however i just want to get the value, if this is from a helper method or using the API thats fine, i dont see the point in having to add another field to my database and keep in sync with my current version field just so i display this...

  6. RICHARD FRIEND
    RICHARD FRIEND avatar
    16 posts
    Member since:
    Nov 2008

    Posted 06 Jul 2009 Link to this post

    Never mind, got it.
    I added the following to the template file.

    public int internalRowVersion
     {
      get
      {
        string ver;
                     string key =  Telerik.OpenAccess.DataObjectKey.Obtain(this);
                     Telerik.OpenAccess.DataObjectKey.Interpret(key, out ver);
                     return int.Parse(ver);
      }
     }

     

  7. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 07 Jul 2009 Link to this post

    Hello Richard,

    I am glad you found a solution, it is very elegant indeed. I initially thought you want to map the field directly.

    Best wishes,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
DevCraft banner