I'm working with the latest version of DotConnect for Oralce and I have this model:
Code: Select all
public class Order
{
public int Id {get;set;}
public int Number {get;set;}
// Other properties
// Relationship with Customer
public int CustomerId {get;set;}
public Customer Customer {get;set;}
}
public class Customer
{
public int Id {get;set;}
// Other properties
// Relationship with CustomerDetails
public CustomerDetails Details {get;set;}
}
public class CustomerDetails
{
public int Id {get;set;}
public string Name {get;set;}
public string Surname {get;set;}
}
Now I have a method that need a single object CustomerDTO done in this way:
Code: Select all
public class CustomerDTO
{
// From Customer
public int Id {get;set;}
// From CustomerDetails
public string Name {get;set;}
public string Surname {get;set;}
}
Now I extract all orders with this query linq:
Code: Select all
var query = MyDbContext.Orders
.Include(x => x.Customer)
.Include(x => x.Customer.Details)
.Select(x => new OrderDTO
{
// Order properties
Customer = new CustomerDTO
{
Id = x.Customer.Id,
Name = x.Customer.Details.Name,
Surname = x.Customer.Details.Surname
}
}
);
Looking with DbMonitor the query, I saw that the join between Customer and CustomerDetails occurs two times (one for each field taken from x.Customer.Details object).
If I took only the Name, the join appears only 1 time.
If I took Name, Surname and Address, it occurs 3 times.
Why?