2016-01-24 79 views
1

我想比较一个AspnetUser ID与注册用户ID。我使用此代码:MVC AspNetUsers比较ID的

try 
     { 
      var userID = HttpContext.Current.User.Identity.GetUserId(); 

      var communityId = (from p in context.UserCommunityRole 
           where p.AspNetUsers= userID 
           select p.CommunityID).FirstOrDefault(); 

      return communityId; 

     } 

但我收到follwoing错误,不明白为什么:

Cannot implicitly converttype 'string'(userID) to Models.AspNetUsers 

任何一个可以帮我这个问题。

回答

0

这个错误是不言自明的,因为它说的是铸造将不可能,因为userIDstring类型,而不是类型AspNetUsers

也许你的意思是下面做这样(考虑到您的AspNetUsers实体有一个名为UserID属性,它是string型)

from p in context.UserCommunityRole 
where p.AspNetUsers.UserID = userID 
+0

是你在哪里赖特。工作很好。谢谢 –