Reverse Mapping with a 1:1 relationship

4 posts, 0 answers
  1. Greg Figueroa
    Greg Figueroa avatar
    82 posts
    Member since:
    Apr 2005

    Posted 05 Jun 2009 Link to this post

    Perhaps I'm missing something, but I don't understand why the following happens.  I will 'try' to keep it simple.

    I have two tables:

    Customer
    CustomerAddress

    In Customer, is a field named BillToAddressID, which contains the ID of the address in the CustomerAddress table.

    I perform a reverse mapping against the tables.

    Everything works great, except for one thing...

    There are other addresses in CustomerAddress, and the user may want to change the Bill To Address to something that already exists in the CustomerAddress table.

    However, this is a problem, because apparently, when you have a one to one relationship with a table (or one to many for that matter), the ID field in the Customer Table (in this case BillToAddressID), is not included in the class that is generated.

    Can someone tell me why?

    I add it back in manually, so when a user wants to change the address, all that needs to be updated is the BillToAddressID in the Customer Table (if it exists in CustomerAddress, of course).

    My question is, why does reverse mapping remove the field?  I completely understand that you don't need it, if you are creating a new customer, and also creating a new Bill To Address, but you are stuck if you want to change that value to another address that exists in the CustomerAddress table.

    Maybe I'm just off my nut, and if I am, can someone please set me straight?

    Thanks, Kuba
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 08 Jun 2009 Link to this post

    Hi Kuba Cole,

    OpenAccess currently provides an object reference to the related field e.g. CustomerAdress in your case. You can access it's Id using Customer.CustomerAddress.Id. In order to set this Id field directly though, there is currently a workaround for direct access to foreign key fields. It is discussed in the following KB article. I must notice though that this workaround is only temporary and this process will be automated and the functionality usable via wizards in one of our next, post Q2 releases.

    I hope the workaround works for you. If you require any additional clarifications, we are looking forward for your future feedback.

    All the best,
    Zoran
    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.
  3. DevCraft banner
  4. Greg Figueroa
    Greg Figueroa avatar
    82 posts
    Member since:
    Apr 2005

    Posted 08 Jun 2009 Link to this post

    Zoran,

       Thanks for the reply.  We had actually already implented what the workaround suggested to get by (we weren't sure however, if the changes would cause other problems... it seems that it doesn't).  I'm glad to see that the option will be available in the future.  It is particularly annoying for us at the moment as we are in the first stages of development on a new project.  As such, changes to the database are rather frequent.  It gets pretty tedious having to add that stuff back in manually.

    Thanks again...

    Kuba
  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 10 Jun 2009 Link to this post

    Hello Kuba Cole,

    Yes, we admit that it is not very convenient to do these manual changes to the generated code. That is way we are doing our best to have the proper code generated as soon as possible. We will notify you when we have the functionality, even if it is before a major release.

    Regards,
    Zoran
    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