?
Solved

How to do a join with Lync and Entity Framework v4.0

Posted on 2015-02-08
3
Medium Priority
?
58 Views
Last Modified: 2016-06-23
I have a sql server database from which I have created an edmx file in my csharp project. The database has all the requisite foreign keys setup and I can see these as NavigationProperties in the XML view of the edmx. All tables have come through as entities correctly.

In SQL I can run a query as follows:

SELECT * FROM Card.CardRequest cr
  JOIN product.CompanyProductDesign cpd ON cpd.CompanyProductDesignID = cr.CompanyProductDesignID
  JOIN product.ProductDesignCOntent pdc ON cpd.CompanyProductDesignID = pdc.CompanyProductDesignID

which will return only the rows that have been matched from all tables (in my case 6 rows). However I am struggling to get the same result using EF and Lync.

I have got the following code in my c# program:

                using (PrepayEntities ent = new PrepayEntities())
                {
                    cardRequests = ent.CardRequest
                                 .Include("CompanyProductDesign.ProductDesignContent")
                                 .Where
                                    (
                                        cr =>
                                            cr.CRIFileCreated == true
                                            &&
                                            cr.CreationEmailSent == false
                                    )
                                .ToList();
                }

which I know includes an extra Where condition but in any case returns all the rows (in my case 6100 rows). I have tried every possibility from examples that I have found the Internet but just can't seem to crack it - I either get 6100 rows or none.

Please can someone point me in the right direction for what I am sure is a simple solution

Thanks
Phil
0
Comment
Question by:LionCalledAlbert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 1000 total points
ID: 40597561
Your LINQ join query should look like:
var result = from cr in ent.CardRequest
join cpd in ent.CompanyProductDesign on cr.CompanyProductDesignID equals cpd.CompanyProductDesignID
join pdc in ent.ProductDesignCOntent on cpd.CompanyProductDesignID equals pdc.CompanyProductDesignID
select new
{
//add more fields as needed
cr.CRIFileCreated,
cr.CreationEmailSent
};

Open in new window


There are more examples using join in this link
0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 1000 total points
ID: 40597566
Hi Phil;

Try this code snippet to see if it gives you what you are looking for.

using (PrepayEntities ent = new PrepayEntities())
{
    cardRequests = ent.CardRequest.
                   Join( CompanyProductDesign, 
                         cr => cr.CompanyProductDesignID,
                         cpd => cpd.CompanyProductDesignID,
                         (cr, cpd) => new
                             {
                              cr = cr,
                              cpd = cpd
                             }
                   ).
                   Join( ProductDesignCOntent,
                         temp => temp.cpd.CompanyProductDesignID,
                         pdc => pdc.CompanyProductDesignID,
                         (temp, pdc) => new
                             {
                               cr = temp.cr,
                               cpd = temp.cpd,
                               pdc = pdc
                             }
                   ).ToList();
}                   

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question