Waqar Ahmed
Waqar Ahmed

Reputation: 1444

Linq To Sql Sub Query Complex

tblItem

tblProduct

tblCategory

My problem is more than one product is return to t2s (Sub-Query). if i add FirstOrDefault() to Sub-Query then it will match it with only one product id! i need to match will all productid(s) it returns.

Upvotes: 1

Views: 85

Answers (2)

Gert Arnold
Gert Arnold

Reputation: 109079

Use the navigation properties that LINQ-to-SQL creates for you. Item should have property Product. So you can simply do this:

var itms = from item in CMP.tblItems
    where item.Name.Contains(Model) && item.Product.CategoryID = CatId
    select new { item.Name };

Upvotes: 0

Hooman
Hooman

Reputation: 192

Try This One:

var itms=from item in CMP.tblItems
         from g in CMP.tblProducts
         where item.Name.Contains(Model) && item.ProductID == g.ProductID && g.CategoryID == CatID
         select new {item.Name};

Upvotes: 1

Related Questions