dotnet-starter-kit
dotnet-starter-kit copied to clipboard
Model relationship with ApplicationUser
Could you please help me create a Order class which belongs to User?
I tried as below but the ApplicationUser is part of Infrastructure project which should not be imported in Domain Project as per architecture.
` public class Order : AuditableEntity, IAggregateRoot { .... public Guid UserId{ get; set; }
public virtual ApplicationUser User { get; set; } } ` I am missing something or doing it wrong way?
Using DDD principles you shouldn't link Aggregate Roots. The Order and ApplicationUser are aggregate roots.
As a rule of thumb an Aggregate should only reference other aggregates by their Id. That means you shouldn't add navigation properties to other aggregates (this prevents different aggregates manipulating each other and leaking business logic to each other).
You should explicitly query the ApplicationUser by the UserId if you need to get User information
If you have OrderLine class then this would be an entity class and you could therefore attached to the Order class i.e.
public class Order : AuditableEntity, IAggregateRoot
{
....
public Guid UserId{ get; set; }
public Collection<OrderLine> OrderLines {get; set;}
}
Hope that helps :-) Kevin