Trouble with custom entities

Posts   
 
    
JayH
User
Posts: 3
Joined: 27-Dec-2004
# Posted on: 27-Dec-2004 23:55:19   

In my scenario, I have three entities: Project, Contact, and ProjectContact (a many-to-many relationship).

I would like to create a new ContactEntity class to provide such things as formatted names, etc. I think have done this and created the necessary factory class successfully as shown below.

public class MyContactEntityFactory : ContactEntityFactory
{
    public override SD.LLBLGen.Pro.ORMSupportClasses.IEntity Create()
    {
        return new MyContactEntity();
    }

}

public class MyContactEntity : ContactEntity
{
    public string ContactName_SalFirstNickLastTitle{}
    public string ContactName_SalFirstNickLast{}
    public string ContactPhone{}
}

In my code I am receiving a ProjectEntity and using it to lookup the ProjectContactCollection. Then I iterate through that collection and want to receive a MyContactEntity through the ProjectContactEntity.Contact property.

What do I need to do to make this work?

I see that the ProjectContactEntity has a EntityFactoryToUse property, but there is no indication of which entity it is referring to (ProjectContactEntity also has a Project property that returns a different entity). Is this used when I request a Contact entity?

As a short term solution, I have been instantiating a new MyContactEntity and then fetching the needed record by the ProjectContactEntity.ContactId, but this is highly undesirable since I can't do any prefetching this way.

I am using C# and the SelfServicing template. I haven't really taken the time to investigate the Adapter template, but understood SelfServicing to be simpler and didn't feel I needed anything complicated. I hope this is possible with SelfServicing because I would not want to switch at this point.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-Dec-2004 13:52:39   

Why don't you add your properties to the derived entity class for Contact in the two-class scenario? I think that's the easiest way to do it.

Frans Bouma | Lead developer LLBLGen Pro
JayH
User
Posts: 3
Joined: 27-Dec-2004
# Posted on: 28-Dec-2004 14:33:52   

Otis wrote:

Why don't you add your properties to the derived entity class for Contact in the two-class scenario? I think that's the easiest way to do it.

Yes, that would be rather easy, wouldn't it? The drawback there is that I can't easily regenerate the code as I have 4 or 5 times up to this point. But if that is the best way to do it...

Thanks, Jay

JayH
User
Posts: 3
Joined: 27-Dec-2004
# Posted on: 28-Dec-2004 17:11:51   

JayH wrote:

The drawback there is that I can't easily regenerate the code as I have 4 or 5 times up to this point.

My buddy Matt pointed out my error offline; I wasn't using the two-class pattern. I'm all set now. Thanks.