New Posts New Posts RSS Feed: Multiple Field Join
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Multiple Field Join

 Post Reply Post Reply
Author
JaxGuyWestside View Drop Down
Newbie
Newbie
Avatar

Joined: 30-Jul-2013
Posts: 2
Post Options Post Options   Quote JaxGuyWestside Quote  Post ReplyReply Direct Link To This Post Topic: Multiple Field Join
    Posted: 30-Jul-2013 at 7:55am
Hello,

I'm trying to write an DevForce LINQ query where I need to join on multiple fields.  I looked in the documentation and found the examples for joins, but I didn't see an example that addressed this specific scenario.  I searched the web for linq queries with multiple field joins and here is what I found which does convey what I'm trying to do; I just need to figure out how to do it for DevForce.

from x in entity
join y in entity2 on new { x.field1, x.field2 } equals new { y.field1, y.field2 }

Any help is greatly appreciated!!
JD
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 30-Jul-2013 at 12:01pm
You should first read this - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/linq-join-examples - to determine whether you really do need a join.  In most models, relationships can be expressed with navigation properties, for example:
  aCustomer.Orders
  anOrder.Customer
 
If you do need to join entities which don't have an existing foreign key relationship, you can do so like you've done above.  For example, here's a contrived example to join Northwind Employees and Users based on their names:
 
var query = from e in entityManager.Employees
             join u in entityManager.Users
             on new { id1 = e.FirstName, id2 = e.LastName } equals new { id1 = u.FirstName, id2 = u.LastName }
             select e;
var results = query.ToList();
 
The types and names of properties in the anonymous types used in the join must be the same, and here the "id1" and "id2" names aren't required.
 
 
 
 
 
Back to Top
JaxGuyWestside View Drop Down
Newbie
Newbie
Avatar

Joined: 30-Jul-2013
Posts: 2
Post Options Post Options   Quote JaxGuyWestside Quote  Post ReplyReply Direct Link To This Post Posted: 31-Jul-2013 at 7:28pm
Thank you for the quick response.  I believe that's basically what I was doing; but I must have had a syntax error of some sort that was causing the problem.  At least I had the right concept.

Thanks again!
JD
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down