AutoMapper binding issues with Entity Framework mapping

automapper c# entity-framework-6 linq-to-entities

Question

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.

1
0
5/14/2016 11:35:34 AM

Accepted Answer

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
0
5/16/2016 3:44:31 PM

Popular Answer

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

Read this answer :

Is automapper preventing lazy loading with EF?



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow