CodeSmith Community
Your Code. Your Way. Faster!

OneToOne Relationship advice

Latest post 12-07-2006 11:55 AM by JJmartin. 3 replies.
  • 12-06-2006 3:36 PM

    • JJmartin
    • Top 25 Contributor
    • Joined on 05-22-2006
    • Phoenix, AZ
    • Posts 164
    • Points 3,275

    OneToOne Relationship advice

    I saw a similar posting to what I am going to ask here dated back in February but there have been a lot of changes since then and I figured it would be worth bringing it up again.

     I have a table with a oneToOne relationship to several other tables ( I have them sharing the primary key of the generic table as their primary key at this point).  What is the current reccommendation to get this inheritance to work in netTiers.

    The suggestion back in February was to use Views and make your custom procs that the view objects would then pick up.  I figured I could use the AliasFile to mask the names of my Specific Object tables.

    Looking for any current suggestions on how to approach this problem.  I am also in a rapid agile development environment and fairly regularly regenerate netTiers and so I am looking for something that is robust enough to handle that.

    -Jeff Martin C# MCSD
    • Post Points: 5
  • 12-07-2006 10:20 AM In reply to

    • JJmartin
    • Top 25 Contributor
    • Joined on 05-22-2006
    • Phoenix, AZ
    • Posts 164
    • Points 3,275

    Re: OneToOne Relationship advice

    So after reviewing the Wiki which sort of addresses this situation I think I am satified that I can use NetTiers as is with my tables as is.  The current problem I am encountering is that the NUnit tests don't seem to be set up for this. 

    The Unit test tries to associate its MockInstance with an existing item that is a foreign key.  But because the foreign key is the Instance's Primary key in this one-to-one relationship, the insert fails because of a duplicate primary key.

     It seems the solution would be to test for the one-to-one relationship and then create a mock instance of the generic table. 

    Has anyone else dealt with this?  Any suggestions on how to alter the template to accomplish this (is there a test for one-to-one relationship in CodeSmith?

    -Jeff Martin C# MCSD
    • Post Points: 35
  • 12-07-2006 10:39 AM In reply to

    Re: OneToOne Relationship advice

    Hi,

    No, there's no current test, and I had noticed the problem with the tests.  This is just a problem that needs to be addressed within the mock instance, check to see if it's a 1:1 relationship, if it is, then handle accordingly.  However, you shouldn't make that a requirement in your unit tests, so maybe we go back to trying to use a mock provider instead.  There's one floating around in the forums that i've been meaning to look into.

    On 12/7/06, JJmartin <bounce-JJmartin@codesmithsupport.com> wrote:

    So after reviewing the Wiki which sort of addresses this situation I think I am satified that I can use NetTiers as is with my tables as is.  The current problem I am encountering is that the NUnit tests don't seem to be set up for this. 

    The Unit test tries to associate its MockInstance with an existing item that is a foreign key.  But because the foreign key is the Instance's Primary key in this one-to-one relationship, the insert fails because of a duplicate primary key.

     It seems the solution would be to test for the one-to-one relationship and then create a mock instance of the generic table. 

    Has anyone else dealt with this?  Any suggestions on how to alter the template to accomplish this (is there a test for one-to-one relationship in CodeSmith?






    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 12-07-2006 11:55 AM In reply to

    • JJmartin
    • Top 25 Contributor
    • Joined on 05-22-2006
    • Phoenix, AZ
    • Posts 164
    • Points 3,275

    Re: OneToOne Relationship advice

    I worked around it in one test so far but haven't altered the template.   Rather than getting a current related record, i create one in the mock instance.   It seems to work fine and as long as i create it on the transaction, it gets rolled back out at the end.

     The other issue i have with the tests is that I have a table with a relationship on  another table that I don't run through NetTiers (aspnet_Roles).  This one seems more problematic to resolve, but I think I will just include those tables for now (of course if I include the Roles table I will need to include all of its related tables or I will run into the same problem.) 

    Any suggestions on that would be helpful.

    -Jeff Martin C# MCSD
    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems