Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model relationship with ApplicationUser #896

Open
nageshkinge opened this issue Oct 16, 2023 · 1 comment
Open

Model relationship with ApplicationUser #896

nageshkinge opened this issue Oct 16, 2023 · 1 comment

Comments

@nageshkinge
Copy link

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?

@KevinFarrow
Copy link

KevinFarrow commented Dec 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants