score:3
I'm not entirely certain that this is what you're looking for, but I'm going to give it a shot:
Try chaining your where clauses in Linq to SQL, and you may get a better result:
List<string> outputRoleUserList =
from rls in roleUserList
from mis in missingRoleUserList
where rls.RoleID != mis.RoleID
where rls.UserID != mis.UserID
select rls.UserID + ",\"" + rls.RoleID
This will actually generate SQL as follows:
rls.RoleId != mis.UserID AND rls.UserId != mis.UserID
However, you have already forced execution on roleUserList and missingRoleUserList, so what you're using in the third Linq statement is not really Linq to SQL but rather Linq to Objects, if I'm reading this correctly.
I'd be curious to see some additional information or clarification and then maybe I'll understand better what's going on!
EDIT: I realized another possibility, it's possible that the object.UserID or object.RoleID is throwing an internal NullPointerException and failing out because one of those values came back null. You could possibly solve this with the following:
List<string> outputRoleUserLIst2=roleUserList
.Where(x => x != null && x.UserID != null && x.RoleID != null && missingRoleUserList
.Where(y => y != null && y.UserID != null && y.RoleID != null && y.RoleID!=x.RoleID && y.UserID!=x.UserID)
.FirstOrDefault()!=null)
.Select(x => x.UserID + ",\"" + x.RoleID).Distinct().ToList();
This is not pretty, and this is the other Linq syntax (with which I am more comfortable) but hopefully you understand what I am going for here. I'd be curious to know what would happen if you dropped this into your program (If I've guessed all of your meanings correctly!). I'll look back in a bit to see if you have added any information!
Source: stackoverflow.com
Related Articles
- C# SQL To Linq - Where Clause with multiple variables Comparison (var1+var2) !=(var1+var2)
- LINQ query with a WHERE clause with multiple conditions
- Linq where clause with multiple conditions and null check
- Linq where clause with multiple conditions
- Linq with where clause in many-to-many EF Code First object
- Multiple level where clause filtering with Linq
- C# - Linq optimize code with List and Where clause
- Using Trim in multiple where clause of linq with Join clause
- LINQ query with multiple conditions in WHERE clause
- How to convert multiple SQL LEFT JOIN statement with where clause to LINQ
- LINQ Join With Multiple Where Clause
- LINQ - Left Outer Join with multiple parameters in Where clause
- linq to entities query which has multiple where clause and one where clause with where in condition
- CRM 2011 LINQ query with multiple inner joins and a single WHERE clause (VB .NET)
- Linq multiple where clause with no or
- SQL to LINQ - multiple tables left outer join with where clause referring right table
- Total Sum with multiple where clause LINQ
- Entity Framework dynamic linq where from generic source with dynamic where clause
- Linq @ Where clause with multiple condition
- Linq where clause with DbFunctions.DiffDays and string comparison not working
- Linq multiple where clause with if condition
- LINQ Join with Multiple Conditions in On Clause
- Multiple WHERE Clauses with LINQ extension methods
- Multiple WHERE clause in Linq
- lambda expression join multiple tables with select and where clause
- using Linq with multiple where conditions
- Linq Query with a Where clause in an Include statement
- linq to sql query with multiple where parameters
- Why C# LINQ expressions must end with Select or Group By Clause where as no such restriction in VB.Net
- LINQ multiple where clause
- How to query Entity Framework objects where select is a list
- Arithmetic calculation using Linq.Expressions yields different results on 32 vs 64bit
- Linq extract a count() value from a data object
- Entity framework IQueryable extension methods do not work as a sub query
- cannot assign to X because it is a 'method group'
- Linq - getting consecutive numbers in an array
- Group by and Count result in LinQ
- What is the equivalent DISTINCT(sql server) in the Linq
- LinqtoSQL SelectMany type arguments cannot be inferred from usage
- How to distinct groups of values?
- Entity Data Model & DataGridView - Creating new objects
- Linq To Sql: Relations not correctly updated
- SQL to LINQ possible?
- C# Linq Lambda Expression for Entity Framework Query Passing Custom Expression to Where Condition
- How to select and count base on a condition of another field using dynamic linq core
- Debugging LINQ statement on QuickWatch or somewhere else
- Linq: DataTable to List. Cast issue
- LINQ Sum method error
- Join two list using LINQ query
- Can we use if statement in linq for deciding to join or not?