我有一个返回以下数据库表结果的查询:
我正在运行的查询正在运行。但是,我只想返回SiteID等于允许用户查看的 SiteID 的结果。
这在下表中定义:
现在,我的查询如下:
User user = ObjectContext.Users
.Include("TeamMemberships")
.First(u => u.UserID == userID);
var teamIDs = user.TeamMemberships.Select(t => t.TeamID).ToList(); //This returns the Users team (Not important for now)
var siteIDs = ObjectContext.SiteMemberships.Where(t => teamIDs.Contains(t.TeamID)).Select(t => t.SiteID).ToList(); //This returns the SiteIDs that the user is allowed to see
int? ticketID = null;
if (string.IsNullOrEmpty(text) == false)
{
if (text.StartsWith("#"))
text = text.Substring(1);
int temp;
if (int.TryParse(text, out temp))
ticketID = temp;
}
var tickets = ObjectContext.Tickets
.Include("TicketPriority")
.Include("TicketStatu")
.Include("TicketType")
.Include("TicketCategory")
.Include("Server")
.Include("Site")
.Include("Detector")
.Include("Detector.Site")
.Include("Detector.Track")
.Include("Team")
.Include("User")
.Include("User1")
.Where(t => ticketID.HasValue ? t.TicketID == ticketID.Value : true)
.Where(t => ticketID.HasValue ? true : t.StartedOn >= fromDate && t.StartedOn <= toDate)
.Where(t => ticketID.HasValue ? true : ticketStatusID.HasValue ? ticketStatusID.Value == 100 ? t.TicketStatusID < 4 : t.TicketStatusID == ticketStatusID.Value : true)
.Where(t => ticketID.HasValue ? true : ticketPriorityID.HasValue ? t.TicketPriorityID == ticketPriorityID.Value : true)
.Where(t => ticketID.HasValue ? true : ticketCategoryID.HasValue ? t.TicketCategoryID == ticketCategoryID.Value : true)
.Where(t => ticketID.HasValue ? true : createdByUserID.HasValue ? t.CreatedByUserID == createdByUserID.Value : true)
.Where(t => ticketID.HasValue ? true : assignedToTeamID.HasValue ? t.AssignedToTeamID == assignedToTeamID.Value : true)
.Where(t => ticketID.HasValue ? true : assignedToUserID.HasValue ? t.AssignedToUserID == assignedToUserID.Value : true);
if (ticketID.HasValue == false && string.IsNullOrEmpty(text) == false)
tickets = tickets.Where(e => e.Title.Contains(text));
return tickets.OrderBy(t => t.TicketID);
现在,我尝试做的是添加一个额外的.Where语句,如:
.Where(t => siteIDs.Contains(t.SiteID));
然而,我一直收到错误:
对...的最佳重载方法匹配有一些无效的参数。
是否会产生此错误,因为我将非可空值与可空值进行比较,或者将其与其他内容进行比较?