Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select Nested with Includes #682

Open
ignaciosalazarcalle opened this issue Mar 4, 2023 · 1 comment
Open

Select Nested with Includes #682

ignaciosalazarcalle opened this issue Mar 4, 2023 · 1 comment

Comments

@ignaciosalazarcalle
Copy link

ignaciosalazarcalle commented Mar 4, 2023

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,

@Hurricane31337
Copy link

I think I have a similar issue:

Classes:

<Table("appointment")>
Public Class appointment
    <ComponentModel.DataAnnotations.Key>
    <Column("id", Order:=0)>
    Public Property id As Integer

    <Column("descriptionid")>
    Public Property descriptionid As Integer?

    <ForeignKey("descriptionid")>
    Public Property description As description
End Class

<Table("description")>
Public Class description
    <ComponentModel.DataAnnotations.Key>
    <Column("id", Order:=0)>
    Public Property id As Integer

    <Column("text")>
    Public Property text As String
End Class

Query:
dbContext.appointments.Include("description").Where(...).OrderBy(...).Select("new(id, description.text)")

Exception:
System.Linq.Dynamic.Core.Exceptions.ParseException: "No property or field 'text' exists in type 'appointment'"

So even though I included the ForeignKey property, Dynamic LINQ does not understand that text is a property of description and not appointment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants