Resizing the Main Window of WPF Applications
C# v.next

LINQ with joins

Dan Wahlin posts about LINQ and Lambdas and Sprocs... Oh My! With his post he defines a complex LINQ query to join several tables from the Northwind database:


public IEnumerable GetOrderDetails(int orderID) {
  NorthwindDataContext db = this.DataContext;
  IEnumerable orderDetails =
    from o in db.Orders
    where o.OrderID == orderID
    join s in db.Shippers on o.ShipVia equals s.ShipperID
    join od in db.OrderDetails on o.OrderID equals od.OrderID
    join p in db.Products on od.ProductID equals p.ProductID
    join supplier in db.Suppliers on p.SupplierID equals supplier.SupplierID
    let total = od.Quantity * od.UnitPrice
    select new OrderDescription
    {
      Product = p.ProductName,
      Quantity = od.Quantity,
      ShipperName = s.CompanyName,
      Total = total,
      UnitPrice = od.UnitPrice,
      SupplierName = supplier.CompanyName
    };
  return orderDetails;
}


Instead of using joins with the LINQ query expression it is also possible to use compound from and access shipper and supplier (with a * to 1 relation) directly:

public IEnumerable GetOrderDetails(int orderID)
{
  NorthwindDataContext db = this.DataContext;
  IEnumerable orderDetails =
    from o in db.Orders
    where o.OrderID == orderID
    from od in o.OrderDetails
    let total = od.Quantity * od.UnitPrice
    select new OrderDescription
    {
      Product = od.Product.ProductName,
      Quantity = od.Quantity,
      ShipperName = o.Shipper.CompanyName,
      Total = total,
      UnitPrice = od.UnitPrice,
      SupplierName = od.Product.Supplier.CompanyName
    };
  return orderDetails;
}

I think the LINQ query with compound from is the simpler one.

Christian

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

buy kamagra

It's really not fair to list this one because the site I'm referring to is still in development. It should launch in the next few weeks. I list it because it's going to be very "top 5" worthy when it launches.

ugg store

a haha. this is too much fun.

chaussure de basket

^-^Many visitors are asking us about how this crisis will affect nonprofits.

Chaussure Jordan

Thank You for posting this. i really enjoyed reading this!!

chaussure basket

When another person pays me an sudden compliment, I normally inform them that they created my day!

Air Jordan Basket

To my mind it is a great article*.*

cl boots

I find life an exciting business,The point is succinctness of expression.

Kamagra

Hey, Really great work,I would like to join your blog anyway so please continue sharing with us..........

louboutin shoes

Really great work,I would like to join your blog anyway so please continue sharing with us.
http://www.redsolelouboutins.com/
http://www.louboutin4u.com/

ゼチーア

Hi there,
Really nice job,There are many people searching about that now they will find enough sources by your tips.
Also looking forward for more tips about that

Christian Louboutin shoes

Could I possibly repost this to one of my blogs on this subject? I will link back to the original, of course. Email me what you think.

Vibram Five Fingers

Hey! I could have sworn I’ve been to this website before but after checking through some of the post I realized it’s new to me. Nonetheless, I’m definitely happy I found it and I’ll be bookmarking and checking back frequently!

Vibram Five Fingers

I personally believe there is a mojo to writing articles that only a few posses and frankly you have it , you genius;

supra shoes

I don’t care how the others who commented here are feeling about your article – I still like it.

loans till payday

There's no word to describe such a great masterpiece. You made such an interesting piece to read, giving every subject an enlightenment for us to gain knowledge and information without any arguments to deal with. Thank you very much and more power!

irs back taxes

I could tell that we’re on the same interest and obsession. Good to know someone I could share my ideas. Looking forward to know and learn some more from you. I'll be glad to share my own thoughts to you soon. Thank you for sharing such valuable articles. More power!

android app developers

There's no word to describe such a great masterpiece. You made such an interesting piece to read, giving every subject an enlightenment for us to gain knowledge and information without any arguments to deal with. Thank you very much and more power!

Trade Forex

Wow!! This is a nice blog and i am very impressed with your blog content. You have shared a nice information with us. I appreciate your work.

pendant lighting

Oh hey I wanted to take the time to say I really like reading your blog.

Alexander McQueen Shoes

I wanted to take the time to say I really like reading your blog.

SEO Services Company


Details are very true and factual, I do really learned something new upon reading this interesting post. Good job! and Thanks!

Cheap Logo Design

This blog is an exact representation of skills. I appreciate the blogger for posting the most excellent thought.

red bottom heel

I like ANMJ on FB & just subscribed to the email feed! :)

sonia

Nice stuff you got, very interesting to read.Well, I do have also in my sleeves, if you have

time don't forget to visit

Spring Electrician

Buy Abilify Online US pharmacy

Thank you for sharing such great information with us. I really appreciate everything that you've done here and am glad to know that you really care about the world that we live in..

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)