简体   繁体   English

EF在特定地图中包含导航属性

[英]EF Include navigation property with specific Map

I have this two classes on EF NET Core wich represent database objects: 我在EF NET Core上有这两个类,它们分别代表数据库对象:

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. 现在,我正在尝试编写一个查询,该查询返回一个Clientes对象,并包括TiposIva属性(导航),但不是全部,仅包含ToEnumerador方法上表示的那些。

In fact I need a Clientes Object with a Enumerador Property filled with related TiposIva data 实际上,我需要一个带有Enumerador属性的Clientes对象,其中填充了相关的TiposIva数据

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. System.InvalidOperationException HResult = 0x80131509 Mensaje =包含属性lambda表达式'c => c.CondicionIva.ToEnumerador()'无效。 The expression should represent a property access: 't => t.MyProperty'. 该表达式应表示属性访问:“ t => t.MyProperty”。 To target navigations declared on derived types, specify an explicitly typed lambda parameter of the target type, Eg '(Derived d) => d.MyProperty'. 要定位在派生类型上声明的导航,请指定目标类型的显式输入的lambda参数,例如'((派生d)=> d.MyProperty')。 For more information on including related data, see http://go.microsoft.com/fwlink/?LinkID=746393 . 有关包括相关数据的更多信息,请参见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[ Origen = Microsoft.EntityFrameworkCore参考:在Microsoft.EntityFrameworkCore.Query.ResultOperators.Internal.IncludeExpressionNode.CreateResultOperator(ClauseGenerationContext子句GenerationContext)在Remotion.Linq.Parsing.Structure.IntermediateModel.ResultOperatorExpressionNodeBase.ApplyNodeSpecrationModel Remotion.Linq.Parsing.Response.Linq.Parsering.Remote.Linq.Parsing.Structure.IntermediateModel.MethodCallExpressionNodeBase.Apply(Reference.Linq.Parsing.Structure.QueryParser.ApplyAllNodes(IExpressionNode节点,ClauseGenerationContext子句GenerationContext) Remotion.Linq.Parsing.Structure.QueryParser.GetParsedQuery(Expression expressionTreeRoot)处的ApplyAllNodes(IExpressionNode节点,ClauseGenerationContext子句GenerationContext)在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, Func 1 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\\OhmioWEBAPINe TResult]( 1 logger, Type contextType) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0 1.b__0()处的表达式查询,IQueryModelGenerator queryModelGenerator,IDatabase数据库,IDiagnosticsLogger 1 logger, Type contextType) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0 1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable [TFunc](对象cacheKey,Func 1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable OhmioRepositorios.ClientesRepository的[TFResult]( 1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable C:\\ Users \\ Eric \\ Documents \\ Fuentes Ohmio WEB \\ Server EF \\ OhmioRepositorios \\ ClientesRepository.cs中的.Cargar(Int32 IdCliente):OhmioServicios.Servicios.Clientes_svc.Cargar(Int32 id)中的第40行\\ Documents \\ Fuentes Ohmio WEB \\ Server EF \\ OhmioServicios \\ Servicios \\ Clientes_svc.cs:OmioWEBAPINetCore.Controllers.ClientesController.GetCliente(Int32 idCliente)的第50行位于C:\\ Users \\ Eric \\ Documents \\ Fuentes Ohmio WEB \\ WEBA \\服务器EF \\ Ohm tCore\\Controllers\\ClientesController.cs:line 38 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext() tCore \\ Controllers \\ ClientesController.cs:Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute的第38行,Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext()上的(Object target,Object []参数)

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. 您不需要在“包含”内调用.ToEnumerador()方法,只需使用TiposIva。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EF 6添加包含导航属性的子句 - EF 6 Add Where Clause To An Include With Navigation Property EF导航属性包括不加载 - EF navigation property include doesn't load EF:同时包含导航属性和排除子导航属性 - EF: Include navigation property and exclude sub navigation property in same time EF:“包含”导航属性,在创建具有“选择”投影的包装器对象时 - EF: “Include” navigation property, when creating a wrapper object with “Select” projection EF:将导航属性包含在DbSet中添加实体的结果中 - EF: Include navigation property to result of adding entity in DbSet EF:包含路径表达式必须引用在类型上定义的导航属性 - EF: The Include path expression must refer to a navigation property defined on the type EF Include始终为第一个导航属性生成INNER JOIN - EF Include always produces INNER JOIN for the first Navigation Property EF core 5 如何在不包含 INCLUDE 的情况下填充导航属性 - EF core 5 how to populate navigation property without INCLUDE 无法使用自动映射器进行 map 内部导航属性。 EF 核心 - Cannot map inner navigation property using automapper. EF Core EF Core:Map 没有导航属性的多对多关系 - EF Core: Map Many to Many relationship without navigation property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM