Contact Us
Forum Home
>
DevForce
>
DevForce 2010
New Posts
FAQ
Search
Calendar
Register
Login
Life without joins?
Post Reply
Author
Message
Share Topic
Printable Version
Delicious
Digg
Facebook
Furl
Google Boomarks
Google Buzz
MySpace
Newsvine
reddit
StumbleUpon
Translate
Twitter
Windows Live
Yahoo Bookmarks
Topic Search
Topic Options
Post Reply
Create New Topic
darrelmiller
Members Profile
Send Private Message
Find Members Posts
Add to Buddy List
Newbie
Joined: 16-Dec-2011
Posts: 3
Post Options
Post Reply
Quote darrelmiller
Report Post
Quote
Reply
Topic: Life without joins?
Posted: 21-Dec-2011 at 6:13am
In
this
documentation page it is suggested that we should be able to avoid joins
to create a more natural looking request. I have run into a case where I don't
see how to do this without joins.
Consider your example of customers and orders. Say I wanted to create a list
of orders and their corresponding sales region where the sales region was a
property of customer.
So, the join syntax would be
query = from o in manager.Orders
join c in manager.Customers on o.CustomerId = c.Id
join sr in manager.SalesRegions on c.SalesRegionId = sr.Id
select new { OrderNumber = o.Number, SalesRegion = sr.Name };
results = query.ToList()
From the examples in your documentation I wasn't able to see how to create a query that projects from more than one entity in the join,
so I was in the process of telling you how it could not be done and I found out how.... So rather than throwing this email away, I'll post
what I think is a solution and maybe someone can tell me if I'm on the right track.
With method chaining,
query = manager.SalesRegions
.SelectMany(sr => sr.Customers)
.SelectMany(c => c.Orders)
.Select(o => new {OrderNumber = o.Number,
SalesRegion = o.Customer.SalesRegion.Name});
Edited by darrelmiller - 21-Dec-2011 at 6:14am
sbelini
Members Profile
Send Private Message
Find Members Posts
Add to Buddy List
IdeaBlade
Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options
Post Reply
Quote sbelini
Report Post
Quote
Reply
Posted: 21-Mar-2012 at 11:30am
Hi darrelmiller,
Sorry for the (very) late reply.
You could also try: (based on NorthwindIBEntities)
var
query = mgr.Orders
.Select(ord =>
new
{orderNumber = ord.OrderID,
salesPersonManager = ord.Employee.Employee2.FirstName});
Regards,
Silvio.
Post Reply
Forum Jump
-- Select Forum --
Community Forum
Community Forum
Community Forum now on StackOverflow
DevForce 2012
DevForce 2010
DevForce 2009
DevForce Classic
Forum Permissions
You
cannot
post new topics in this forum
You
cannot
reply to topics in this forum
You
cannot
delete your posts in this forum
You
cannot
edit your posts in this forum
You
cannot
create polls in this forum
You
cannot
vote in polls in this forum