I've an application in Asp.NET Core 3.1 MVC with EF Core and Identity.
I've two tables Calls
and AspNetUsers
. AspNetUsers
has many Calls
and one Call
has one AspNetUsers
.
The Calls
table structure is okay, I think. But now I need to get Calls
from AspNetUsers
.
In CallsController
I'm trying: IList<Call> calls = this.User.Calls;
but no success.
I tried:
IList<Call> calls = this._context.Calls.Where(x => x.UserId == this._userManager.GetUserId(this.User)).ToList();
I've success. But do it is correct?
So, in application i've identity classes and an ApplicationUser
like this:
public class ApplicationUser : IdentityUser
{
public virtual IList<Call> Calls { get; set; }
}
And in Startup
class in ConfigureServices
method:
services.AddDefaultIdentity<ApplicationUser>(options =>
options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
So, What's the better way to get Calls from AspNetUsers? Thanks!