0
所以我創建了由簡單成員創建的UserProfile表和由我創建的Enrollment表之間的多對多關係。查詢與UserId錯誤的多對多關係 - MVC 4
用戶配置 - > User_Enrollment < - 報名
我想查詢登錄用戶的註冊和我有這樣的代碼:
public ActionResult ListarUCs()
{
var id = Membership.GetUser().ProviderUserKey;
var ucs = db.Enrollments.Where(x => x.Users.Any(r => id.Equals(r.UserId)));
return View(ucs.ToList());
}
作爲用戶的UserProfiles的列表的名稱在註冊模型中。 但它給出了一個錯誤:
Unable to create a constant value of type System.object. Only primitive types or enumeration types are supported in this context
已經嘗試過這種方式:
var userId = User.Identity.GetUserId();
,然後查詢,但不承認User.Identity.GetUserId();
有人可以幫助我嗎?由於
如果使用SimpleMembership,我會建議使用WebSecurity.CurrentUserId以獲取用戶標識或WebSecurity.CurrentUserName來獲取當前登錄用戶的用戶名 – mahlatse