按getuserid过滤数据 [英] Filter data by getuserid

查看:82
本文介绍了按getuserid过滤数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 ;

推荐答案

未经测试,但试试这个



Untested, but try this

var userid = User.Identity.GetUserId();
var crequests = from costingrequests in db.viewCostingRequests
where costingrequests.AspUserAssignedTo == userid
select costingrequests ;


这篇关于按getuserid过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆