您需要按以下方式更改您的课程(我没有对此进行测试):
asp.net core的默认应用用户
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
namespace project.Models
{
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
{
}
}
模型
public class AspNetFriends
{
public int ID { get; set; }
public bool isConfirmed { get; set; }
public virtual ApplicationUser friendFrom { get; set; }
public virtual ApplicationUser friendTo { get; set; }
}
现在您可以访问 aspnet 用户的 getter 和 setter
控制器
public async Task<IActionResult> Details(int id)
{
var query = from m in _dbContext.AspNetFriends
join ff in _dbContext.Users on
new { m.friendFrom.Id } equals new { Id = cu.Id }
join ft in _dbContext.Users on
new { m.friendTo.Id } equals new { Id = cu.Id }
where m.ID == id
select m;
return View(query.Single());
}
看法
@model project.AspNetFriends
<p>
@model.friendFrom.UserName
</P>
@item.CreationUser.UserName