score:2
Accepted answer
context.table1
.join(table2, a => a.id, b => b.id, (a, b) => {table1 = a, table2 = b})
.where(ab => ab.table2.col1.equals("abc"))
.select(ab => {
outletcd = ab.table1.id,
name = ab.table1.name,
addrline1 = ab.table1.addrline1,
addrline2 = ab.table1.addrline2,
city = ab.table1.city,
zip = ab.table1.zip,
statecd = ab.table1.statecd,
ctrycd = ab.table1.ctrycd,
country = ab.table1.country,
phone = ab.table1.phone,
});
score:1
var results = context.table1
.where( a => a.b.col1.equals("abc")
.select( x => new sampledto {
outletcd = a.id,
//other cols
})
.tolist();
foreach( var sampledto in results ) {
sampledto.table2 = context.table2.where( x => x.condition ).tolist();
}
score:1
// groupjoin teachers and students:
var result = context.teachers.groupjoin(context.students,
teacher => teacher.id, // from each teacher take the id
student => student.teacherid, // from each student take the teacherid
// when they match, group the teacher and all his matching students:
(teacher, students) => new
{ // make a new object:
// get some teacher properties
name = teacher.name,
addrline1 = teacher.addrline1,
...
// make a table from the columns from all the teacher's students:
table2 = students
.select(student => new
{
col1 = student.col1,
col2 = student.col2,
})
// here it is clearly to see that col1 comes from student
// i don't want all students, only those with abc for col1, so:
.where(studentcolumns => studentcolumns.col1.equals("abc"));
Source: stackoverflow.com
Related Query
- How to filter LINQ query based on child table column?
- How to filter LINQ query by table column and get count
- LINQ Query to dynamically filter database where child table column equals optional input value
- Filter parent/child table (one to many association) in linq query based on entities in child table?
- How to select column from child table in linq
- How can I filter results of one LINQ query based on another?
- How to order items based on a column in child table in EF
- How to query Link table based data in LINQ
- How do I use LINQ to filter AND manipulate results based on values intersecting between a child and comparer?
- How to filter linq query based on all of the values of one property from another list
- How do I sum a column in a child table of a projected linq query?
- How to create a dynamic linq query for filter based on ria service?
- How to query a table column into an array with LINQ
- How to select a column based on date condition in LINQ query
- How to count write the linq query when the grouped bY column is in one table and the items are in another table
- Query to filter data based conditions in child table
- How to pull one column from second table in Linq query with join
- LINQ query grouping by column in child table and ordering the results within the groups
- Linq how to query a list of items for a combined list of a child collection based on a property of the parent item
- How can we get list of two column say firstname and lastname from customer table in mvc using linq query
- C# LINQ to XML - How can I filter nodes based on a child element?
- How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load()
- Linq To Entities - how to filter on child entities
- In LINQ query, how to order by included table column using .Include()?
- how to take 100 records from linq query based on a condition
- How to write LINQ query with column name as parameter still in a type safe way
- how do I write LINQ query to retrieve distinct records based on only specific properties?
- filter a linq query based on the results of another query's results
- how to create a pivot table with dynamic column using linq tree expression
- How to use LINQ to filter property of child collection using (.Any())
More Query from same tag
- LINQ result form 1:* relationship table -ASP.NET
- Are these enumerations code functionally the same?
- Need to initialize an integer linq expression
- Linq selecting sub results using select
- This method is not supported against a materialized query result
- Is it possible to use LINQ to check if all numbers in a list are increasing monotonically?
- How to return Linq query result from asynchronous method
- Group by array contents
- How to sort upon <TEntity> unknown dynamic generic List?
- Linq: Model does not bind properly to Database View(query with UNION)
- C# LINQ calculated Group By
- How to pass func expression in LINQ where clause?
- joining on null to find missing elements
- How to improve this query performance in Linq?
- C# + Deedle: Creating a Data Series with Continuous DateTime Keys from Another with Date Gaps using LINQ
- How to convert Generic List<anonymous type > to Generic List <SubToSubMenu>?
- Using Linq to query data based on dictionary object in C#
- Populating Gridview with DropDownList
- Filling an object list with multiple queries
- LINQ Compare two arrays and return the position and values that do not match
- C# Join two tables using Include. Data comes from a Model
- Does LINQ perform subsequent Selects in memory?
- retrieving data by LINQ c#
- How can i use the select method for Multiple properties with same property name
- How do I perform aggregation without the "group by" in Linq?
- get Invalid object name while executing a UDF
- IComparable implementation for list of students and linq Max and Min methods
- LINQ how to return last date and difference between first and last count
- Why cannot type arguments be inferred from this simple code?
- Conditional projection with LINQ to Entities