Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have tables here

SQL
create table Product(
Pro_id int primary key,
Pro_Name varchar(50)
)

create table Order(
Order_id int primary key,
Pro_id int foreign key references Product(Pro_id),
DateOfOrder Date,
Quantity int check(Quantity > 0)
)

How can I select "Pro_Name" that is ordered and "all of record in table Orde"r (using LinQ)?
Posted
Updated 15-Apr-15 14:46pm
v3

Learn to do it yourself:
LINQ (Language-Integrated Query)[^]
 
Share this answer
 
You would require something like this

SQL
var p =   (from o in db.Order
          join prod in db.Product
          on o.pro_id equals prod.pro_id
          orderby prod.pro_name
          select new
          {
            prod.pro_name,
            o.dateoforder,
            o.quantity,
            o.order_id
          });
 
Share this answer
 
v2
Comments
Sascha Lefèvre 15-Apr-15 9:22am    
You don't need to "select new" if you only select one field. Just select prod.pro_name
John C Rayan 15-Apr-15 9:28am    
I agree and as I said in my solution "something like this". It depends how the op implements in the code. Thanks anyway.
Bùi Long Nghĩa 15-Apr-15 20:17pm    
Thanks. You know that if I just select from the table Product, I will not be able to know what products are ordered.
John C Rayan 16-Apr-15 1:52am    
Because the product from order table joined with product table you will see only the products that are ordered
Bùi Long Nghĩa 16-Apr-15 2:38am    
How can I do if I want to select "Pro_Name" and all of column in table Order?
C#
//An alternative in fluent syntax
var pro_names = db.Order.Join(db.Product,o=>o.pro_id,p=>p.pro_id,(o,p)=>new {p.pro_name}).
OrderBy(a=>a.pro_name);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900