How do I map an OData query against a DTO to another entity?

后端 未结 5 488
梦谈多话
梦谈多话 2020-12-05 01:30

My question is very similar to this one: How do I map an OData query against a DTO to an EF entity? I have a simple setup to test the ASP.NET Web API OData V4 $filter functi

5条回答
  •  温柔的废话
    2020-12-05 01:59

    Try using AutoMapper, you will need to add these references to your controller

    using AutoMapper;
    using AutoMapper.QueryableExtensions;
    

    Your method

    [EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
    public IQueryable Get()
    {
        return dbContext.Entities.ProjectTo();
    }
    

    In your global

    protected void Application_Start()
    {
            //Usually in a diff class Mapping.ConfigureDataTransferObjects();
            Mapper.CreateMap();
            Mapper.CreateMap();
    }
    

提交回复
热议问题