title: Returning Domain Objects from Repositories on Joining tables
body: <p>I have been reading that Repositories should return domain objects only. I am having difficulty with implementing this. I currently have API with Service Layer, Repository and I am using EF Core to access sql database. </p>
  
  <p>If we consider User(Id, Name, address, PhoneNumber, Email, Username) and Orders (id, OrderDetails, UserId) as 2 domain objects. One Customer can have multiple Orders. I have created navigation property</p>
  
  <pre><code>public virtual User User{ get; set; }
  </code></pre>
  
  <p>and foreign Key. </p>
  
  <p>Service layer needs to return DTO with OrderId, OrderDetails, CustomerId, CustomerName. What should the Repository return in this case? This is what i was trying:</p>
  
  <pre><code>public IEnumerable&lt;Orders&gt; GetOrders(int orderId)
          {
              var result = _context.Orders.Where(or=&gt;or.Id=orderId)
                  .Include(u =&gt; u.User)
                  .ToList();
              return result;
          }
  </code></pre>
  
  <p>I am having trouble with Eager loading. I have tried to use include. I am using Database first. In the case of above, Navigation Properties are always retuned with NULL. The only way i was able to get data in to Navigation Properties was to enable lazy loading with proxies for the context. I think this will be a performance issue</p>
  
  <p>Can anyone help with what i should return and why .Include is not working? </p>