title: DbContext & Auto mapper - An exception was thrown while attempting to evaluate a LINQ query parameter expression
body: <p>This is helper which i used for initializing the Automapper :</p>
  <pre><code>public interface IAutoMapperConfig
      {
          MapperConfiguration CreateMapperConfig&lt;T&gt;() where T : Profile, new();
      }
  
  public class AutoMapperConfig :IAutoMapperConfig
  {
      public  MapperConfiguration CreateMapperConfig&lt;T&gt;() where T : Profile, new()
      {
          var config = new MapperConfiguration(cfg =&gt;
          {
              cfg.AddProfile(new T());
          });
          return config;
      }
  }
  </code></pre>
  <p>And i called helper method in one of my Repository and passing mapping profile to CreateMapperConfig.</p>
  <pre><code>    public class ClosedOrderRepository : IclosedOrders
      {
          private readonly OrdersContext _ordersContext;
          private readonly IAutoMapperConfig _autoMapperConfig;
  
          public ClosedOrderRepository(OrdersContext orderContext, IAutoMapperConfig autoMapperConfig)
          {
              _autoMapperConfig = autoMapperConfig;
              _ordersContext = orderContext;
  
          }
  
      public List&lt;ClosedOrdersDTO&gt; SalesInvoiceOrders() //thrown exception here 
      {
          var config = _autoMapperConfig.CreateMapperConfig&lt;ClosedOrderProfile&gt;();
  
          var SalesInvoiceOrdersDB= _ordersContext.SalesLine
                  .Where(f =&gt; f.Type == 2)
                  .ProjectTo&lt;ClosedOrdersDTO&gt;(config)
                  .Take(100)
                  .ToList();
          return SalesInvoiceOrdersDB;
      }
  
  }
  </code></pre>
  <p>Here is mapping profile. As you can see, some of the mappings are using the <code>DbContext</code>, so I have to somehow inject it in the ClosedOrderProfile</p>
  <pre><code>public class ClosedOrderProfile : Profile
  {
      private readonly OrdersContext _ordersContext;
      public ClosedOrderProfile(OrdersContext orderContext)
      {
          _ordersContext = orderContext;
  
      }
      public ClosedOrderProfile()
      {
          CreateMap&lt;Sales_Invoice_Line, ClosedOrdersDTO&gt;()
          .ForMember(r =&gt; r.NumberofItems, opt =&gt; opt.MapFrom(src =&gt; src.Quantity))
          .ForMember(r =&gt; r.SerialNumber, opt =&gt; opt.MapFrom(src =&gt; _ordersContext.item_Ledger_Entries
                      .Where(serial=&gt;serial.Entry_No_ == src.Value_Entry.Item_Ledger_Entry_No_)
                      .Select(no=&gt;no.Serial_No_).ToList()));
      }
  
  }
  </code></pre>
  <p>Here is Startup class:</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
             services.AddScoped&lt;IAutoMapperConfig, AutoMapperConfig&gt;();
             services.AddAutoMapper(typeof(Startup));
          }
  </code></pre>
  <p>But, When i run the code i will get this error :</p>
  <blockquote>
  <p>An exception was thrown while attempting to evaluate a LINQ query
  parameter expression. To show additional information call
  EnableSensitiveDataLogging() when overriding DbContext.</p>
  </blockquote>
  <p>Can anyone please help me or point me into the right direction :)
  Thanks.</p>