Create an object that is a subclass of an existing object

Posts   
 
    
bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 05-Feb-2010 01:24:55   

Example: 1. I have 3 classes. User and Contact. 2. Contact inherits from User and User inherits from Person. 3. I create an instance of a User object. 4. Later someone wants to make a Contact out of that user.

Is there a way to do this? Currently when I try to save a new Contact using the Id of an existing User, I get a primary key violation error in my Person table.

Thanks,

Billy Jacobs

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Feb-2010 04:39:23   

Contact in a child of User, so Contact can exist without an User. This means that every time you create a Contact, a User is created as well. The same is for Person parent.

What you can do is add another Contact entity to your LLBLGen project (Contact2, for instance). Such entity doesn't inherit from User, just reference it. That way you can create a Contact which will create only a contact row in db:

Contact2Entity myContact = new Contact2Entity();
myContact.User = theUser;
David Elizondo | LLBLGen Support Team
bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 05-Feb-2010 17:16:53   

I could do that but I want the Contact to be a User. My workaround was to create a stored procedure and insert only the contact information with the same ID as the user.

I was hoping that LLBLGen had a mechanism to handle this situation.

Thanks,

Billy Jacobs

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Feb-2010 04:20:51   

bjacobs wrote:

I could do that but I want the Contact to be a User. My workaround was to create a stored procedure and insert only the contact information with the same ID as the user.

Yep. That's a way. If you look at my suggestion it's similar, you will end up with 2 Contact entities: Contact (is part of the inheritance) and Contact2 (no part of the inheritance, just there for inserting isolated Contacts). Anyway, good you workaround this.

bjacobs wrote:

I was hoping that LLBLGen had a mechanism to handle this situation.

Here is a verbose discussion about that subject in case you want to know why LLBLGen doesn't support this: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=14835

David Elizondo | LLBLGen Support Team