问题描述
Hello all
我试图通过AspUserAssignedTo过滤记录,它与User.Identity.GetUserID()相同的值
var crequests =来自db.viewCostingRequests中的costingrequests
其中costingrequests.AspUserAssignedTo == User.Identity.GetUserId()
选择成本计算请求;
我收到的错误消息是;
System.NotSupportedException :'LINQ to Entities无法识别方法'System.String GetUserId(System.Security.Principal.IIdentity)'方法,并且此方法无法转换为商店表达式。'
如何解决此问题或如何正确处理这种情况?
我尝试过的事情:
var crequests =来自db.viewCostingRequests中的成本请求
其中c ostingrequests.AspUserAssignedTo ==HOWDOIGETUSERID
选择costingrequests;
Hello all
I am trying to filter records by AspUserAssignedTo which will have the same value as User.Identity.GetUserID()
var crequests = from costingrequests in db.viewCostingRequests
where costingrequests.AspUserAssignedTo == User.Identity.GetUserId()
select costingrequests ;
the error message I receive is;
System.NotSupportedException: 'LINQ to Entities does not recognize the method 'System.String GetUserId(System.Security.Principal.IIdentity)' method, and this method cannot be translated into a store expression.'
What do I do to resolve this issue or how do I address this situation correctly?
What I have tried:
var crequests = from costingrequests in db.viewCostingRequests
where costingrequests.AspUserAssignedTo == "HOWDOIGETUSERID"
select costingrequests ;
推荐答案
var userid = User.Identity.GetUserId();
var crequests = from costingrequests in db.viewCostingRequests
where costingrequests.AspUserAssignedTo == userid
select costingrequests ;
这篇关于按getuserid过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!