views:

45

answers:

1

Can I join the list object in .net collection with the enity object in EF for example

   var prodts = from req in Product
               join prod in context.ProductApplications on req.ProductGUID equals prod.ProductGUID 
              slect req;

Product is the lsit object. and context.ProductApplications is the Enity object.

Can I join them , can any one please let me know how to join themm

A: 

You can do that, yes. Alternative method-chaining syntax:

var prodts = Product.
             Join(
                  context.ProductApplications,
                  req => req.ProductGUID,
                  prod => prod.ProductGUID,
                  (req, prod) => req
                 );

This returns IEnumerable<Product>. The Join method takes IEnumerable<> as the first parameter, so what is going to actually happen is the DB will get queried and context.ProductApplications will be fetched and the results will be enumerated. The resulting object will be used for "joining" with your Product collection.

Update

According to your comments, you have some GUIDs in the Product(s?) collection and you want to fetch all the entities from context.ProductApplications that "match" those GUIDs (correct me if I am wrong). If that's the case, you don't really need a join.

var prodts = context.
             ProductApplications.
             Where(pa => Product.
                         Select(p => p.ProductGUID).
                         Contains(pa.ProductGUID)
                  );
Yakimych
thanks for your answer, i have slightly diffrent problem,in my database i have one temp table which contains some GUIDs,i want to find the all products in the database which have the Same GUIDs in temp table.product table is huge, for that i do simple join the datbase and retive the data.if i want to do it in enity framework in MT, i created one list collection and joining with the product enity just as you mentioned above. but it is timming out while feteching the data from the database it self.hope you understand the probelm, any there a way in enity framework to solve
Krishna Kishore
No, I don't really understand the problem, could you try to structure your explanation differently perhaps? Those points are pretty fuzzy right now: `"i created one list collection and joining with the product enity"` - as far as I see, you have a collection of products (it's called `Product`, btw, is it a typo? Should it be `Products`?), and a collection of ProductApplications (fetched on-the-fly). You join them with `LINQ` and get the resulting collection. Correct me if I am wrong. The other fuzzy sentence is this: `but it is timming out while feteching the data from the database it self`
Yakimych
ok let me rephrase, when i use join which you have mentioned above, it is throwing the error saying time out while fectching the rows from database, i mean while fecthing the rows from context.ProductApplications enity. because the ProductApplications table in database is very huge.how can i fix this.
Krishna Kishore