How to define 1:1 relationship

Posts   
 
    
Posts: 4
Joined: 24-May-2018
# Posted on: 24-May-2018 14:36:47   

Hello,

I am an user of LLBLGen Pro from way back who has recently inherited a project that uses LLBLGen Pro 2.6. The generated classes in source code control do not match the LGP file we have (i.e. the LGP file we have is outdated).

I am attempting to update the LGP file to match the database and more closely match the existing generated classes so that the rest of the system will compile with newly generated classes. By looking at the generated classes in source control, I see that someone defined a custom 1:1 relationship between a table and view. The table is named Application and the view is named VwJobQuestionSummary. These should join on Application.Id and VwJobQuestionSummary.ApplicationId.

Here's a snippet of the generated classes that show it is a 1:1 relationship.

    /// <summary>Returns a new IEntityRelation object, between ApplicationEntity and VwJobQuestionSummaryEntity over the 1:1 relation they have, using the relation between the fields:
    /// Application.Id - VwJobQuestionSummary.ApplicationId
    /// </summary>
    public virtual IEntityRelation VwJobQuestionSummaryEntityUsingApplicationId
    {
        get
        {
            IEntityRelation relation = new EntityRelation(SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToOne, "VwJobQuestionSummary", true);

            relation.AddEntityFieldPair(ApplicationFields.Id, VwJobQuestionSummaryFields.ApplicationId);

But here's my challenge. I go into the LLBL model wizard and try to add this relationship, I select "Add new 1:1/1:n/m:1 relationship" but no matter what I do, I can't get it to create the relationship as 1:1. It always creates it as 1:n. I have confirmed that the view does not contain more than one row with the same ApplicationId.

Can you guide me on how to indicate that I want the relationship to be created as 1:1 instead of 1:n?

Thanks very much for you help, Dave Weber

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 24-May-2018 19:07:36   

When you map the view to an entity, the field you are joining on (ApplictionID) should be marked as the PK in the designer on the entity (part of the identifying fields)

Posts: 4
Joined: 24-May-2018
# Posted on: 30-May-2018 13:02:14   

Thank you. That makes sense. I appreciate the help.