score:2
Accepted answer
In your code You define 2 list CurrentCaseList,CurrentControlList
but not define CaseSelectionList
.
To get the 3 controls that matches one case, for this see below code:
the SelectMany
method to select all orders where TotalDue
is less than 500.00.
Here is the code:
decimal totalDue = 500.00M;
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
ObjectSet<Contact> contacts = context.Contacts;
ObjectSet<SalesOrderHeader> orders = context.SalesOrderHeaders;
var query =
contacts.SelectMany(
contact => orders.Where(order =>
(contact.ContactID == order.Contact.ContactID)
&& order.TotalDue < totalDue)
.Select(order => new
{
ContactID = contact.ContactID,
LastName = contact.LastName,
FirstName = contact.FirstName,
OrderID = order.SalesOrderID,
Total = order.TotalDue
}));
foreach (var smallOrder in query)
{
Console.WriteLine("Contact ID: {0} Name: {1}, {2} Order ID: {3} Total Due: ${4} ",
smallOrder.ContactID, smallOrder.LastName, smallOrder.FirstName,
smallOrder.OrderID, smallOrder.Total);
}
}
Source: stackoverflow.com
Related Articles
- Linq code to select one item
- linq how to select a parent with a child collection that contains one or many of an array (or list) of values
- How to Select All with a One to Many Relationship Using Linq
- LINQ Source Code Available
- Linq lambda expression many to many table select
- C# LINQ Select Many
- Linq Select many where property x exists in externalList
- creating Linq to sqlite dbml from DbLinq source code
- Conditionally Insert Where Clause in LINQ Method Syntax with Select Many
- Avoiding duplicate code in Linq Select method
- LINQ Select Many statement
- Linq to sql - Join 2 tables, select 1 row from right table with a 1 to many relationship
- One to Many LINQ query - Assembly does not have definition for SELECT
- Bind a Linq Lambda Select Many from Controller to view in MVC4? What are the Best ways to return in view
- Select data in many to many relationship in Linq
- How to Select top (5) contributors group by Business type code in c# linq query
- LINQ to SQL select exact matching record from many to many table
- source code for LINQ 101 samples
- How to write aggregate query in LINQ reusing part of the select code
- how to give DTO to LINQ select many query in c#
- SQL/ Linq query select from many to many
- how to write a Linq query with a EF code first Many to Many relationship
- LINQ (lambda syntax) select for many to many relationships
- Linq using the index from a select many query
- LINQ how do I specify select certain columns in a one to many joins
- how to select data by linq in many-to-many relationship in First code Entity framework 5
- Having trouble with a many to many linq select
- LINQ Select Statement making many SQL Calls
- Linq select many into new column
- How to write C# LINQ code to select based on condition
- Copy values between objects
- Cascading dropdownlist with mvc and jQuery not working
- Extra Columns While Converting Linq Result into Data Table
- LINQ Select from two Collections with same length
- What is the method syntax for this LINQ, is it a join, and if not then what is it?
- EqualityComparer in LINQ - how can I do?
- MVC Update Details Controller
- OrderBy specific elements in List
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- How to insert data with entiity Framework core when the id is autogenerated?
- Finding the difference between two DataTables
- "A cycle was detected in the set of changes" When trying to add a circularly linked list to the database
- Linq projection how to check for null collection from select statement
- selecting repeated values from distinct group using LINQ
- Passing A DbSet<T> created at runtime via reflection to Queryable
- Returning an anonymous type when using context.Object.SqlQuery
- How to improve this query performance in Linq?
- How to wrap Entity Framework to intercept the LINQ expression just before execution?
- LINQ Conditional Sum
- "better" (simpler, faster, whatever) version of 'distinct by delegate'?