score:3
Accepted answer
int requiredId = ...
var usersInReqdDept = Users.Where(u => u.Departments
.Any(d => d.DepartmentId == requiredId));
If the Departments
list can be null
, you will need a null-check in the Where
clause.
If you want to search the Departments
list instead,
int requiredId = ...
var usersInReqdDept = Departments.Single(d => d.DepartmentId == requiredId)
.Users;
Of course, this will throw an exception if such a department doesn't exist.
Source: stackoverflow.com
Related Query
- How to get Users who only have some specific department id, Linq
- How to fetch some specific XML nodes present only in few parents using LINQ for XML?
- How to get only specific field from the list
- Using a LINQ Where query to get only some of the ConfigurationManager.ConnectionStrings
- how do I write LINQ query to retrieve distinct records based on only specific properties?
- How to get only Date from datetime column using linq
- I am trying create a new list of users from a list of users who have not created an additional object with a certain property using LINQ
- How to get SQL query into LINQ form in C# code
- How can you use LINQ to find Azure AD users with specific licenses using the Azure AD Graph API Client Library 2.0
- How to retrieve Users with a specific role via Linq in ASPnet Identity
- NHibernate to Linq Get Authors who have not written books
- How to include only some items of internal list with LINQ to Entities
- C# LINQ How to get a data source from a db?
- c# get list of users that have a specific foreign key
- how can get List of users in active directory using LINQ to LDAP?
- How to get only two fields from the table by linq query?
- c# How to use linq to get xml string by filtering some data?
- How to get list of all ApplicationUsers who are in certain Role from database by LINQ expression?
- Using Linq to get records that have specific foreign key
- How do I use LINQ to get all the Items that have a particular SubItem?
- How to get PEX to automatically generate inputs for code involving LINQ
- How do I get Linq to return identical repeated rows only once?
- How to get latest id only from database using LINQ in ASP.NET Core Web API?
- Using Linq how do get a list of users and their last login from two tables
- How to I use LINQ to get last date only
- Using only Linq or Lambda, how do I combine both pieces of code to return List<Entity> e?
- LINQ to XML. How to get some string?
- Linq How to get the master record and a specific field of inner details record
- Linq Foreign Key | How to display only the elements with a specific foreign key?
- How to write a LINQ to only get rows that match a certain condition dependant on columns shown?
More Query from same tag
- Context duplication on nested call to linq operations
- How to relate entities without navigation property mappings
- Linq ISNULL functionality
- Merge two or more T in List<T> based on condition
- filter a datatable to contain unique columns
- XML to dropdown list using LINQ
- How to convert a String[] to an IDictionary<String, String>?
- LINQ to Subsonic Left Outer Join
- Parsing a text File using Linq
- Transpose Data in C# Business Objects
- Using Linq, how to GroupBy against objects in a list within the target object
- How to write a variable to an XML file?
- IN and NOT IN with Linq to Entities (EF4.0)
- How to call method/function in where clause of a LINQ query as IEnumerable object
- GroupBy to identify items with different scores and the number of times they are assigned different scores
- Entity Framework: Linq where clause compare date and time value with seconds difference
- c# changing this line so it outputs the string as a variable
- Inner join two lists based on a child list
- linq getting datarow and iterating each field based on Column
- how to outer join in F# using FLinq?
- C# WebAPI Cross update inner join data with multiple tables
- How to write multiple statments in select method of lambda expressions
- Combining two double[] arrays into double[,]
- Asp.Net MVC3, Update query in Linq
- LINQ join between List of integers and IQueryble causes StackOverflow Exception in c#
- Partial Class Properties not accessable through LINQ query bound to GridView
- Linq Group by, Concatenate and load child entities on a list
- Why does the c#(web) linq syntax is different in vb(windows) linq syntax?
- From T-Sql to Linq-to-SQL
- How to group by with only Time format in Linq