简体   繁体   中英

AutoMapper binding issues with Entity Framework mapping

I'm using AutoMapper as an ORM in application with Entity Framework v6.

My problem statement is that if I executes a single query via LINQ to Entities on any single entity and maps entity data via AutoMapper with DTO, many other queries will be executed at the same time while data binding.

Kindly anyone let me know, how to avoid this problem.

I think this may happens due to the lazy loading enabled.

Read this answer :

Is automapper preventing lazy loading with EF?

This is expected behavior. Remember, AutoMapper just looks at the destination type and will map matching properties from the source type. If you don't want some properties to be mapped lazily, you have several options:

  1. Remove the properties from the destination model
  2. Use Include to eagerly fetch properties
  3. Use LINQ projection in AutoMapper (ProjectTo) to force EF to use the Select LINQ projection to grab whatever data it needs to based on the source type

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM