question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lazy Loading after mapping

See original GitHub issue

I use Entity Framework and I want to map navigation properties to my DTO’s. So, my question is EF’s navigation properties by default have Lazy loading, its possible with auto mapper after mapping to have the same functionality of lazy loading to my DTO’s.

Here is my DTO’s :

    public class CustomerDTO
    {
        public string CustomerID { get; set; }
        public string CompanyName { get; set; }
        public ICollection<Order> Orders { get; set; }
     }

    public class OrderDTO
    {
        public int OrderID { get; set; }
        public string CustomerID { get; set; }
        public int? EmployeeID { get; set; }
        public string ShipName { get; set; }
        public string ShipAddress { get; set; }
        public Employee Employee { get; set; }
        public Customer Customer { get; set; }
        public  ICollection<OrderDetail> OrderDetails { get; set; }
    }

    public class OrderDetailDTO
    {
        public int OrderID { get; set; }
        public decimal UnitPrice { get; set; }
        public short Quantity { get; set; }
        public Order Order { get; set; }
    }
    
     public class EmployeeDTO
    {
        public int EmployeeID { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public ICollection<Order> Orders { get; set; }
    }

Persistent Models:

    public class Customer
    {
        public string CustomerID { get; set; }
        public string CompanyName { get; set; }
        public ICollection<Order> Orders { get; set; }
     }

    public class Order
    {
        public int OrderID { get; set; }
        public string CustomerID { get; set; }
        public int? EmployeeID { get; set; }
        public string ShipName { get; set; }
        public string ShipAddress { get; set; }
        public Employee Employee { get; set; }
        public Customer Customer { get; set; }
        public  ICollection<OrderDetail> OrderDetails { get; set; }
    }

    public class OrderDetail
    {
        public int OrderID { get; set; }
        public decimal UnitPrice { get; set; }
        public short Quantity { get; set; }
        public Order Order { get; set; }
    }
    
     public class Employee
    {
        public int EmployeeID { get; set; }
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public ICollection<Order> Orders { get; set; }
    }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jbogardcommented, May 18, 2017

I’ve changed ORMs several times on various projects, and I promise you, layering and indirection makes it MUCH harder to do so, even impossible.

On Thu, May 18, 2017 at 5:46 AM Efstathios Chrysikos < notifications@github.com> wrote:

My intention is to separate completely the ORM Layer from my model. One reason to do this is because maybe in the future the Project Leader will decide to change the ORM. So, to achieve this, I don’t want my repositories to return or take Persistent Model directly but Domain Model which will mapped to PM and after submitted for the specific job to the ORM?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AutoMapper/AutoMapper/issues/2113#issuecomment-302355815, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMkYOMuyBc64TQ2sfSWjr3gcKwgZZks5r7BN4gaJpZM4Ne8-0 .

0reactions
lock[bot]commented, May 6, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy load map when they come into the viewport
lazy loading normally means "loading on demand", so, as you say, for example when the map will come into the viewport, whereas your...
Read more >
Lazy Loading of Related Data - EF Core
Lazy loading can cause unneeded extra database roundtrips to occur (the so-called N+1 problem), and care should be taken to avoid this. See...
Read more >
How to lazy load and initialize elements using an ...
I have a site with a few Leaflet maps here and there and I realized that initializing even a few maps on page...
Read more >
Lazy loading React components
The concept of lazy loading is simple: initialize objects that are critical to the user interface first and quietly render noncritical items ...
Read more >
Increase the Performance of your Site with Lazy-Loading ...
If the lazy-loaded content hasn't been loaded it won't show up when printing the page. The same can happen when the page is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found