score:6
Accepted answer
you are pretty close: all you need to do is selecting ids, and then using contains
, like this:
var supplierproductids = db.supplierproducts
.where(w => w.supplierid == supplierid)
.select(p => p.productid)
.tolist(); // you could get better performance without tolist
ienumerable<products> products = db.products
.where(w => supplierproductids.contains(w.productid))
.tolist();
score:0
if you have constructed you model correctly you should have the virtual property for products in supplier class
public virtual icollection<product> products {get; set;}
and this would have made your task easier:
db.suppliers.where(s => s.id == supplierid).select(s => s.products)
Source: stackoverflow.com
Related Query
- Lambda Expression - How to provide values to where clause from an IEnumerable<Object>?
- How to extract a where clause expression tree from IQueryable
- Get lambda expression from where clause or IQueryable/IEnumerable
- How can I create an Lambda Expression for Linq in the Where clause for two tables after the Join?
- How can I pull a repeated where clause expression from linq into a function?
- lambda expression join multiple tables with select and where clause
- Async Await in Lambda expression where clause
- How to get unique string from a lambda expression
- How to get the where clause from IQueryable defined as interface
- How to get leaf node from a nested collection using lambda expression
- How to query by where clause with EF code first
- How can I get data from a list with a where clause to another list?
- How to use an expression with a generic func lambda in a linq where clause?
- How to provide default values in select clause of a query in LINQ to NHibernate
- Selectively remove from where clause in LINQ expression tree
- How can I check for null values in this linq query where clause
- LINQ Expression - Dynamic From & Where Clause
- How to create dynamic lambda based Linq expression from a string in C#?
- How to substitute Expression<Func<T,bool>> into where clause of linq to sql expression
- How to extract max(property) from left join in LINQ with lambda expression
- Where clause on field outside Lambda expression class in Linq
- How to write the same code using Lambda Expression
- How to write following code in lambda expression or linq?
- How can I keep the the logic to translate a ViewModel's values to a Where clause to apply to a linq query out of My Controller?
- how can i return model property from lambda expression (like mvc's "html.textboxfor(yyy)")?
- How to use a lambda expression to return a field from two collections
- Using LINQ and EF, how to remove values from database where not in list of items
- How to return only rows where no rows from another table using Lambda Expressions in C#
- How to return multiple rows using LINQ lambda expression from SQL Server 2014?
- How to create where clause only by Expression
More Query from same tag
- convert data in to ToList()
- Why does this LINQ statement return null and not a IEnumerable with count=0
- LINQ compare values for the same year , different month and doing a count if value has changed
- linq, selecting columns as IEnumerable<DataRow>
- Include Nested Tables in LINQ Method syntax
- How to do the conditional order by with LINQ
- Calling a user defined function in a LINQ query
- LINQ OrderBy not ordering .. changing nothing .. why?
- Custom compare dictionaries using LINQ
- WHERE is not being included in the LINQ-query
- Count duplicate rows in a datatable using vb.net
- LINQ Logical join VS inner join
- How to optimize this loop into one linq query removing the loop call entirely?
- Multiple join with groupby in linq
- Partial update in Web API is not working
- Complex sort order using entity framework
- Does LINQ To SQL auto update the LOCAL/CLIENT id column after a SubmitChanges call?
- The server response was: 5.7.0 Authentication Required. Learn more at
- LINQ, iterators, selecting and projection
- LINQ Outer Joins Dynamic OrderBy
- If null then set it to empty string lambda expression in linq
- Dynamic Linq queries with sorting, nulls at end
- linq to datatable incorrect column calculation
- query xml using xsd attributes
- Log all linq queries executed on DbContext - C#
- How to do a wildcard DataTable select with lambda/LINQ using question marks?
- How do I Grab Selected Index on two Dropdownlist's OnSelectedIndexChanged?
- How to avoid repeating property projections when using EF Core inheritance?
- LINQ query output groups and subgroups in JSON
- Convert Objects into Hierarchy based on Number Sequence