I have a Core 2.0 project that has reached the point where I need to start linking users to the data I have. It started as a one user test bed that now requires me to have multiple per user.
User Model:
public class ApplicationUser : IdentityUser
{
public virtual ICollection<Balance> Balances { get; set; }
}
Balance model:
public virtual ApplicationUser User { get; set; }
...
ApplicationDbContext.cs:
//Users to balances
builder.Entity<ApplicationUser>()
.HasMany(b => b.Balances)
.WithOne(u => u.User);
In my code, when creating a new Balance, I cannot figure out how to link my current logged in user:
var myNewBalance = new Balance();
myNewBalance.User = User;
^ boom
How do I relate Balances to the currently logged in user?