I have this two classes on EF NET Core wich represent database objects:
public partial class Clientes
{
public int IdCliente { get; set; }
public TiposIva CondicionIva { get; set; }
}
public partial class TiposIva
{
public int IdCondicionIva { get; set; }
public string Descripcion { get; set; }
public string Letra { get; set; }
public string Fiscal { get; set; }
public Enumerador ToEnumerador() {
return new Enumerador { ID = this.IdCondicionIva, Valor = this.Descripcion };
}
}
Now I'm trying to write a query that return a Clientes object, and include TiposIva property (navigation), but not all of them, Only the ones represented on ToEnumerador Method.
In fact I need a Clientes Object with a Enumerador Property filled with related TiposIva data
I try this:
return this.RepositoryContext.Clientes
.Include(c => c.CondicionIva.ToEnumerador())
.FirstOrDefault();
But I get this error:
System.InvalidOperationException HResult=0x80131509 Mensaje = The Include property lambda expression 'c => c.CondicionIva.ToEnumerador()' is invalid. The expression should represent a property access: 't => t.MyProperty'. To target navigations declared on derived types, specify an explicitly typed lambda parameter of the target type, E.g. '(Derived d) => d.MyProperty'. For more information on including related data, see http://go.microsoft.com/fwlink/?LinkID=746393. Origen = Microsoft.EntityFrameworkCore Seguimiento de la pila: at Microsoft.EntityFrameworkCore.Query.ResultOperators.Internal.IncludeExpressionNode.CreateResultOperator(ClauseGenerationContext clauseGenerationContext) at Remotion.Linq.Parsing.Structure.IntermediateModel.ResultOperatorExpressionNodeBase.ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext) at Remotion.Linq.Parsing.Structure.IntermediateModel.MethodCallExpressionNodeBase.Apply(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext) at Remotion.Linq.Parsing.Structure.QueryParser.ApplyAllNodes(IExpressionNode node, ClauseGenerationContext clauseGenerationContext) at Remotion.Linq.Parsing.Structure.QueryParser.ApplyAllNodes(IExpressionNode node, ClauseGenerationContext clauseGenerationContext) at Remotion.Linq.Parsing.Structure.QueryParser.GetParsedQuery(Expression expressionTreeRoot) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger
1 logger, Type contextType) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0
1.b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1 source) at OhmioRepositorios.ClientesRepository.Cargar(Int32 IdCliente) in C:\Users\Eric\Documents\Fuentes Ohmio WEB\Server EF\OhmioRepositorios\ClientesRepository.cs:line 40 at OhmioServicios.Servicios.Clientes_svc.Cargar(Int32 id) in C:\Users\Eric\Documents\Fuentes Ohmio WEB\Server EF\OhmioServicios\Servicios\Clientes_svc.cs:line 50 at OhmioWEBAPINetCore.Controllers.ClientesController.GetCliente(Int32 idCliente) in C:\Users\Eric\Documents\Fuentes Ohmio WEB\Server EF\OhmioWEBAPINetCore\Controllers\ClientesController.cs:line 38 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext()
It will not work that way. "Include" you can only use navigation properties. You don't need call .ToEnumerador() method inside "Include", use only TiposIva.
User contributions licensed under CC BY-SA 3.0