LLBLGen version 5.1.1
Adapter
Platform: .NET 4.5.2
Language: C#
Framework: DTO Class Model
Preset: SD.DTOClasses.ReadOnlyDTOs
SQL Server
I have a entity model with 3 entities:
Client (ClientId int PK, Name varchar(10))
Project (ProjectId int PK, Name varchar(10), ClientId int FK)
Section (SectionId int PK, Name varchar(10), ProjectId int FK)
In other words, a Section has 1 related Project, and a Project has a 1 related Client.
I'm using the designer to create a Derived Model based on Section. In the tree in the "Derived Element Sub-Element Selection" area, I choose the fields I want from Section, then open the "Project" subtree and select Name and ProjectId. Then, within the "Project" subtree, I open the "Client" sub-sub tree and select Name and ClientId.
Next, in the "Derived Element Shape Editor", I select the Project's Name and Id fields and press "De-normalize selected fields". Those fields move into the main Element. I then select the Client's Name and Id fields and press "De normalize selected fields" twice - once to move them up to the Project embedded element, and again to move them into the main Element.
At this point, I'm done, so I save the project.
If I look at the project file at this point, all seems well, and it's saving the nested relationships as expected:
<Field Name="ProjectName">
<EntityField Name="Name" Entity=":Project" NavigatorPath="Project" />
</Field>
<Field Name="ProjectProjectId">
<EntityField Name="ProjectId" Entity=":Project" NavigatorPath="Project" />
</Field>
<Field Name="ClientClientId">
<EntityField Name="ClientId" Entity=":Client" NavigatorPath="Project,Client" />
</Field>
<Field Name="ClientName">
<EntityField Name="Name" Entity=":Client" NavigatorPath="Project,Client" />
</Field>
I then generate the code.
In the DTO, all seems good and the comments are correct:
/// <summary>Gets or sets the ClientClientId field. Derived from Entity Model Field 'Client.ClientId'</summary>
[DataMember]
public System.Int32 ClientClientId { get; set; }
/// <summary>Gets or sets the ClientName field. Derived from Entity Model Field 'Client.Name'</summary>
[DataMember]
public System.String ClientName { get; set; }
/// <summary>Gets or sets the ProjectName field. Derived from Entity Model Field 'Project.Name (Project)'</summary>
[DataMember]
public System.String ProjectName { get; set; }
/// <summary>Gets or sets the ProjectProjectId field. Derived from Entity Model Field 'Project.ProjectId (Project)'</summary>
[DataMember]
public System.Int32 ProjectProjectId { get; set; }
But in the Persistence class, it's wrong:
private static System.Linq.Expressions.Expression<Func<GreaterGiving.Data.AdapterData.EntityClasses.SectionEntity, GreaterGiving.Data.Audit.DtoClasses.SectionAudit>> CreateProjectionFunc()
{
return p__0 => new GreaterGiving.Data.Audit.DtoClasses.SectionAudit()
{
ClientClientId = p__0.ClientId,
ClientName = p__0.Name,
ProjectName = p__0.Project.Name,
ProjectProjectId = p__0.Project.ProjectId,
SectionId = p__0.SectionId,
};
}
Note that the 2 "Project" fields are correct - they correctly get their data from properties of p__0.Project. But the "Client" fields are wrong. For example, ClientName is set from p__0.Name, but it should be p__0.Project.Client.Name.
Thus, the generated code doesn't compile.