none
Returning a list of objects from a join of 2 different tables RRS feed

  • Question

  • Hi, I'm trying to return some list containing objects from 2 tables and I can't translate this to linq syntax.

    "With Product_value AS 

    (SELECT oi.Order_id, oi.quantity*p.price AS Value 

    FROM Order_item AS oi INNER JOIN Product AS p 

    ON oi.Product_id=p.Product_id) 

    SELECT o.Order_id, SUM(pv.Value) AS Total 

    FROM Product_value AS pv 

    INNER JOIN Order AS o 

    ON pv.Order_id=o.Order_id 

    WHERE o.Order_id=@order_id 

    GROUP BY o.Order;

     

    The problem is when I'm returning a List<Product> there is an error it cannot transform it from System.Generic.List 

    Product is class I created with the needed attributes.

    pls anyone help :(

    Friday, June 17, 2011 3:29 PM

Answers

  • var list= (from t in table

    join t1 in table1

    where...

    select new Product{}).ToList();


    Best Regards,
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by AncaP Tuesday, June 21, 2011 10:46 AM
    Monday, June 20, 2011 11:12 AM

All replies

  • Hello AncaP,

    Thanks for your post.

    According to your description, I think you could try to use the AsEnumerable() method. Just as the following sample:

    var query = (from q in q.Orders.AsEnumerable()

                      where...

                     select q).ToList();

    I hope this can help you.

     

    have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 20, 2011 9:49 AM
    Moderator
  • var list= (from t in table

    join t1 in table1

    where...

    select new Product{}).ToList();


    Best Regards,
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by AncaP Tuesday, June 21, 2011 10:46 AM
    Monday, June 20, 2011 11:12 AM