我有4个表Transactions
,Attachment
,SubReportType
& SubRepRole
。我在我的缓存中拥有用户角色。我想有那些与用户角色相关附件[用户可以拥有多个角色]LINQ查询WHERE IN clasue
List<int> userrole = new List<int>();
UserContext user_details = (UserContext)HttpContext.Current.Cache["UserContext"];
IList<UserRole> userrole_id = user_details.UserRoleModuleWise;
var query = (from trans in objContext.Transactions
join attch in objContext.Attachment on trans.TransId equals attch.TransId
join subrept in objContext.SubReportType on trans.SubRepId equals subrept.SubRepId
join subreprl in objContext.SubRepRole on trans.SubRepId equals subreprl.SubRepId
join selectedrole in userrole_id on subreprl.RoleId equals selectedrole.RoleId
/*where obj.Contains(subreprl.RoleId) */orderby trans.TransDate
select new AttachmentModel
{
Createdate = attch.CreatedDateTime,
FileType = attch.FileType,
FileName = attch.FileName,
Attachid = attch.AttachedId,
FileTag = attch.FileTag,
Transid = trans.TransId,
SubReportName = subrept.SubRepName,
RandomPinNo = attch.FileRandomPin
}).ToList();
现在收到此错误:
Unable to create a constant value of type 'User.Common.DataContract.UserRole'. Only primitive types or enumeration types are supported in this context.
这个请大家帮忙。也尝试过“包含”,但类型转换错误即将到来。只是想要在user_details.UserRoleModuleWise中有角色的记录。 user_details.UserRoleModuleWise是角色ID和角色名
你想要检查/ *哪里obj.Contains(subreprl.RoleId)*。 –