none
Linq to sql help with join RRS feed

  • Question

  • I'm newbie to Linq to sql i have this query

    join o in OrderDetails
        on c.OrderID equals o.OrderID
        join prod in Products
        //join Products
        on  o.ProductID equals prod.ProductID
        where c.CustomerID == "VINET"
        select  new { c.CustomerID  ,
         //o.UnitPrice , o.Quantity,
         o.UnitPrice , o.Quantity ,
                          o.ProductID,o.OrderID ,
                          prod.ProductName ,
                          //o.(o=>o.UnitPrice * o.Quantity)
                         o.(o=>o.UnitPrice *o.Quantity)   
                          }
        it games error i want to output  o.UnitPrice *o.Quantity

    How this can be done

    Thank you in advanced

    Friday, July 15, 2011 10:05 AM

Answers

  • Hi,

    Try to give it a name:

    	from c in Orders
    	join o in OrderDetails
    	on c.OrderID equals o.OrderID
    	join prod in Products
    	on o.ProductID equals prod.ProductID 
    	where c.CustomerID == "VINET"
    	select new { c.CustomerID , 
    	 o.UnitPrice , o.Quantity , 
    	 x = (o.UnitPrice * o.Quantity) ,
    					 o.ProductID,o.OrderID ,
    					 prod.ProductName  
    					 }
    

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    • Proposed as answer by Crick3t Monday, July 18, 2011 9:51 AM
    • Marked as answer by Jackie-SunModerator Wednesday, August 3, 2011 9:45 AM
    Friday, July 15, 2011 10:42 AM
  • Hi Simon,

     

    If I understand right, then you want a UnitPrice * Quantity in your query's output.

    If I am right than you should try something like this:

     

    join o in OrderDetails
     on c.OrderID equals o.OrderID
     join prod in Products
     on o.ProductID equals prod.ProductID
     where c.CustomerID == "VINET"
     select new { 
       CustomerID = c.CustomerID,
       UnitPrice = o.UnitPrice, 
       Quantity = o.Quantity,
       ProductID = o.ProductID,
       OrderID = o.OrderID,
       ProductName = prod.ProductName ,
       InventoryValue = o.UnitPrice * o.Quantity
       }
    

     


    The InventoryValue will contain the o.UnitPrice *o.Quantity.

    HTH


    Regards, Peter

    //If a post answers your question, please click "Mark As Answer".
    //Also if a post seems to be helpful, please click "Mark as Helpful" on that post.

    • Proposed as answer by Crick3t Monday, July 18, 2011 9:51 AM
    • Marked as answer by Jackie-SunModerator Wednesday, August 3, 2011 9:45 AM
    Friday, July 15, 2011 10:48 AM

All replies

  • Hi,

    Try to give it a name:

    	from c in Orders
    	join o in OrderDetails
    	on c.OrderID equals o.OrderID
    	join prod in Products
    	on o.ProductID equals prod.ProductID 
    	where c.CustomerID == "VINET"
    	select new { c.CustomerID , 
    	 o.UnitPrice , o.Quantity , 
    	 x = (o.UnitPrice * o.Quantity) ,
    					 o.ProductID,o.OrderID ,
    					 prod.ProductName  
    					 }
    

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    • Proposed as answer by Crick3t Monday, July 18, 2011 9:51 AM
    • Marked as answer by Jackie-SunModerator Wednesday, August 3, 2011 9:45 AM
    Friday, July 15, 2011 10:42 AM
  • Hi Simon,

     

    If I understand right, then you want a UnitPrice * Quantity in your query's output.

    If I am right than you should try something like this:

     

    join o in OrderDetails
     on c.OrderID equals o.OrderID
     join prod in Products
     on o.ProductID equals prod.ProductID
     where c.CustomerID == "VINET"
     select new { 
       CustomerID = c.CustomerID,
       UnitPrice = o.UnitPrice, 
       Quantity = o.Quantity,
       ProductID = o.ProductID,
       OrderID = o.OrderID,
       ProductName = prod.ProductName ,
       InventoryValue = o.UnitPrice * o.Quantity
       }
    

     


    The InventoryValue will contain the o.UnitPrice *o.Quantity.

    HTH


    Regards, Peter

    //If a post answers your question, please click "Mark As Answer".
    //Also if a post seems to be helpful, please click "Mark as Helpful" on that post.

    • Proposed as answer by Crick3t Monday, July 18, 2011 9:51 AM
    • Marked as answer by Jackie-SunModerator Wednesday, August 3, 2011 9:45 AM
    Friday, July 15, 2011 10:48 AM
  • Thank  you all .
    Sunday, July 17, 2011 9:56 PM