2

I have a many-to-many query problem in Linq-to-SQL.

I have a table named user.

User has got 2 products > join product.UserID and Product can be have 2 equipment. Product to Equipments have many to many association

I want to get user's equipments:

 var match =  from c in ctx.Products                              
    where c.UserID == USERID
    select c.Equipments;

This code returns IQueryable<System.Data.Objects.DataClasses.EntityCollection<Equipments>> typed object.

But I want to get IQueryable<Equipments> typed object. How can I cast?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
halit
  • 1,128
  • 1
  • 11
  • 27

1 Answers1

4

It sound like you want SelectMany.

var match =  from c in ctx.Products                              
    where c.UserID == USERID
    from e in c.Equipments
    select e;

match is IQueryable<Equipments> now

leppie
  • 115,091
  • 17
  • 196
  • 297