Hi Frans,
I'm using your Derived Models templates which work fine. So my question is more help in general, maybe you would, I hope.
In some cases I have some extra metadata which are needed in the outcome of the generated code. I can now regenerate the code which you generate for my special cases. But I have this one thing I can't fix. I have this lambda created by LLBLGen:
private static System.Linq.Expressions.Expression<Func<VA.Pac.DomainData.EntityClasses.ProjectEntity, VA.Pac.DomainData.Aggregates.DtoClasses.RechtenProjectSearchRoot>> CreateProjectionFunc()
{
return p__0 => new VA.Pac.DomainData.Aggregates.DtoClasses.RechtenProjectSearchRoot()
{
ProjectId = p__0.ProjectId,
ProjectStatusId = p__0.RechtProject.ProjectStatusId,
RechtLicentieContracten = p__0.MBRechtLicentieContracten.Select(p__1 => new VA.Pac.DomainData.Aggregates.DtoClasses.RechtenProjectSearchRootTypes.RechtLicentieContract()
{
ContractLicentieTypeId = p__1.ContractLicentieTypeId,
ContractVernieuwen = p__1.ContractVernieuwen,
LandId = p__1.LandId,
LicentieContractSoortId = p__1.LicentieContractSoortId,
RechtLicentieContractId = p__1.RechtLicentieContractId,
}).ToList(),
// __LLBLGENPRO_USER_CODE_REGION_START ProjectionRegion_RechtenProjectSearchRoot
// __LLBLGENPRO_USER_CODE_REGION_END
};
}
I have a problem with this, because I cannot recreate it that way.
RechtLicentieContracten = p__0.MBRechtLicentieContracten.Select(p__1 => new VA.Pac.DomainData.Aggregates.DtoClasses.RechtenProjectSearchRootTypes.RechtLicentieContract()
{
ContractLicentieTypeId = p__1.ContractLicentieTypeId,
ContractVernieuwen = p__1.ContractVernieuwen,
LandId = p__1.LandId,
LicentieContractSoortId = p__1.LicentieContractSoortId,
RechtLicentieContractId = p__1.RechtLicentieContractId,
}).ToList(),
I'm only able to create one level. I can create all classes seperately, but not in a hierarchy. Given this, I can create this:
private static System.Linq.Expressions.Expression<Func<VA.Pac.DomainData.EntityClasses.ProjectEntity, VA.Pac.RootDto.RechtenProjectSearchRoot.RechtenProjectSearchRoot>> CreateRechtenProjectSearchRootProjectionFunc()
{
return alias => new VA.Pac.RootDto.RechtenProjectSearchRoot.RechtenProjectSearchRoot()
{
ProjectId = alias.ProjectId,
ProjectStatusId = alias.RechtProject.ProjectStatusId,
RechtLicentieContracten = alias.MBRechtLicentieContracten.Select(x => x.ProjectToRechtLicentieContract()).ToList(),
};
}
and in a different (or the same (partial) class, i can decide), the call to the select:
public static partial class RechtLicentieContractLinqProjection
{
private static readonly System.Linq.Expressions.Expression<Func<VA.Pac.DomainData.EntityClasses.MBRechtLicentieContractEntity, VA.Pac.RootDto.RechtenProjectSearchRoot.RechtLicentieContract>> RechtLicentieContractProjectorExpression = CreateRechtLicentieContractProjectionFunc();
private static readonly Func<VA.Pac.DomainData.EntityClasses.MBRechtLicentieContractEntity, VA.Pac.RootDto.RechtenProjectSearchRoot.RechtLicentieContract> CompiledRechtLicentieContractProjector = CreateRechtLicentieContractProjectionFunc().Compile();
public static IQueryable<VA.Pac.RootDto.RechtenProjectSearchRoot.RechtLicentieContract> ProjectToRechtLicentieContract(this IQueryable<VA.Pac.DomainData.EntityClasses.MBRechtLicentieContractEntity> baseQuery)
{
return baseQuery.Select(RechtLicentieContractProjectorExpression);
}
public static VA.Pac.RootDto.RechtenProjectSearchRoot.RechtLicentieContract ProjectToRechtLicentieContract(this VA.Pac.DomainData.EntityClasses.MBRechtLicentieContractEntity entity)
{
return CompiledRechtLicentieContractProjector(entity);
}
private static System.Linq.Expressions.Expression<Func<VA.Pac.DomainData.EntityClasses.MBRechtLicentieContractEntity, VA.Pac.RootDto.RechtenProjectSearchRoot.RechtLicentieContract>> CreateRechtLicentieContractProjectionFunc()
{
return alias => new VA.Pac.RootDto.RechtenProjectSearchRoot.RechtLicentieContract()
{
ContractLicentieTypeId = alias.ContractLicentieTypeId,
ContractVernieuwen = alias.ContractVernieuwen,
LandId = alias.LandId,
LicentieContractSoortId = alias.LicentieContractSoortId,
RechtLicentieContractId = alias.RechtLicentieContractId,
};
}
}
But this way all underlying properties of the entity "RechtLicentieContract" are retrieved, although most are not used in the Derived Model.
This must have something to do with the Expression<Func<. But I can't get my head around it.
What would be the way to go? Would you have a code sample?
Thanks