我在我的项目中有一个文章实体,其中有名为"Author"的 "ApplicationUser" 属性。如何获取当前登录 "ApplicationUser" 的完整对象?在创建新文章时,我必须将
在旧的 Membership 机制中,这很简单,但在新的 Identity 方法中,我不知道该怎么做。我尝试以下方式:
1. 添加使用Identity扩展的语句:
来源=EntityFramework
Article
中的 Author
属性设置为当前的 ApplicationUser
。在旧的 Membership 机制中,这很简单,但在新的 Identity 方法中,我不知道该怎么做。我尝试以下方式:
1. 添加使用Identity扩展的语句:
using Microsoft.AspNet.Identity;
2. 然后尝试获取当前用户: ApplicationUser currentUser = db.Users.FirstOrDefault(x => x.Id == User.Identity.GetUserId());
但我得到了以下异常:'System.String GetUserId(System.Security.Principal.IIdentity)' 方法无法转换为存储表达式。来源=EntityFramework