Search code examples
aspnetboilerplate

ASP.NET BoilerPlate: How to detach entity object from context?


How to detach entity object from context?

  1. Unable to get access to the context in my application service
  2. How to clone a row using asp.net boilerplate? e.g. I have row say row1 with primary key Id I want to insert same row contents with new Id

Solution

    1. You can access DbContext in repository (should not use DbContext in application service). Create custom repository, define some methods that you want to use in application service layer, see document here

    2. To clone object, you can create copy method in the entity class or use AutoMapper.