Skip to content

Select Nested with Includes #682

Open
@ignaciosalazarcalle

Description

@ignaciosalazarcalle

Hello,

I'm trying resolve this query with DynamicLinq:

select u.nombre
from expediente e
inner join clave_principal cp on cp.id = e.clave_principal_id
inner join area_unidad au on au.id = cp.area_unidad_id
inner join unidad u on u.id = au.unidad_id
where e.id = 38269

I have a datatable with 4 fields:

  • TableName: Expediente
  • Select: ClavePrincipal.AreaUnidad.Unidad.Nombre as NombreUnidad???
  • Where: Id == @0
  • Include: ClavePrincipal.AreaUnidad.Unidad

And I want get the value the select field dynamically.
I construct a Queryable from TableName and I transform these fields:

if (!string.IsNullOrWhiteSpace(parametroPlantilla.Where))
{
    listQueryableEntity = listQueryableEntity
        .Where(parametroPlantilla.Where, request.ExpedienteId);
}

if (!string.IsNullOrWhiteSpace(parametroPlantilla.Include))
{
    listQueryableEntity = listQueryableEntity
        .Include(parametroPlantilla.Include);
}

List<dynamic> listEntity = Enumerable.Empty<dynamic>().ToList();
if (!string.IsNullOrWhiteSpace(parametroPlantilla.Select))
{
    ParsingConfig parsingConfig = new ParsingConfig
    {
        NullPropagatingUseDefaultValueForNonNullableValueTypes = true,
        PrioritizePropertyOrFieldOverTheType = false
    };
    listEntity = await listQueryableEntity
        .Select(parsingConfig, parametroPlantilla.Select)
        .ToDynamicListAsync(cancellationToken: cancellationToken);
}

My classes:

public class Expediente
{
	public int Id {get;set;}
	public string Nombre {get;set;}
	public int ClavePrincipalId {get;set;}
	public ClavePrincipal ClavePrincipal {get;set;}
}

public class ClavePrincipal
{
	public int Id {get;set;}
	public string Nombre {get;set;}
	public int AreaUnidadId {get;set;}
	public AreaUnidad AreaUnidad {get;set;}
}

public class AreaUnidad
{
	public int Id {get;set;}
	public string Nombre {get;set;}
	public int UnidadId {get;set;}
	public Unidad Unidad {get;set;}
}

public class Unidad
{
	public int Id {get;set;}
	public string Nombre {get;set;}
}

I'm using .Net 6 ant the last System.Linq.Dynamic.Core = 1.3

Regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions