I've got Entity Framework Code First Entities:
public class Customer
{
public long Id { get; set; }
public ICollection<ServiceAccount> Accounts { get; set; }
}
public class Service
{
public long Id { get; set; }
}
public class ServiceAccount
{
public long Id { get; set; }
public Customer Customer { get; set; }
[Required()]
public Service Service { get; set; }
}
It is supposed that a Customer has some Accounts for the Services. But there can be some default Accounts, which are not bounded to any Customer. And each Account is used for a concrete Service. This Entities have the following Configuration:
// Customer Configuration:
base.ToTable("Customers");
base.HasKey(x => x.Id);
base.HasMany(x => x.ServiceAccounts)
.WithOptional(x => x.Customer)
.WillCascadeOnDelete();
// For Service:
base.ToTable("Services");
base.HasKey(x => x.Id);
// For Account:
base.ToTable("Accounts");
base.HasKey(x => x.Id);
base.HasOptional(x => x.Customer)
.WithMany(x => x.Accounts);
base.HasRequired(x => x.Service)
.WithMany();
The problem is, when I load a Customer, all his Accounts are loaded too, but they have their Service set to null. Why it is not loaded?
Thanks in advance