首页 > 其他分享 >AutoMapper Explicit expansion

AutoMapper Explicit expansion

时间:2022-08-23 12:22:37浏览次数:109  
标签:configuration dest Explicit expansion AutoMapper LineItems

Explicit expansion

In some scenarios, such as OData, a generic DTO is returned through an IQueryable controller action. Without explicit instructions, AutoMapper will expand all members in the result. To control which members are expanded during projection, set ExplicitExpansion in the configuration and then pass in the members you want to explicitly expand:

dbContext.Orders.ProjectTo<OrderDto>(configuration,
    dest => dest.Customer,
    dest => dest.LineItems);
// or string-based
dbContext.Orders.ProjectTo<OrderDto>(configuration,
    null,
    "Customer",
    "LineItems");
// for collections
dbContext.Orders.ProjectTo<OrderDto>(configuration,
    null,
    dest => dest.LineItems.Select(item => item.Product));

For more information, see the tests.

 

标签:configuration,dest,Explicit,expansion,AutoMapper,LineItems
From: https://www.cnblogs.com/chucklu/p/16615715.html

相关文章

  • AutoMapper Queryable Extensions
    QueryableExtensionsWhenusinganORMsuchasNHibernateorEntityFrameworkwithAutoMapper’sstandardmapper.Mapfunctions,youmaynoticethattheORMwil......