Using a cartesian product in LINQ and Entity framework to combine 3 tables
-
before I return "set.select" I would like to include fields from another table but I canot join this table because it has no fields in common with the other two tables. How may I adjust my code below to achieve this? Iam using vs2012 sql and in MVC c# var set = (from m in managers from t in context.tblCompany join tsc in context.tblStyling on t.ccID equals tsc.ccID select new { tsc.ccID,LogoIcon = tsc.Icon , tsc.style1, tsc.style2, t.Desc }) .ToList(); return set.Select(c => new Settings(c.ccID, c.style1, c.style2, c.Desc, c.LogoIcon , m.firstName , m.lastName));
-
Answer:
Okay, it looks like you want to join context.tblCompany and context.tblStyle and get the cross product of the resulting set and managers. If that is correct, then you are already there. You just need to include the fields from manager that you want in your select statement: var set = (from m in managers from t in context.tblCompany join tsc in context.tblStyling on t.ccID equals tsc.ccID select new { tsc.ccID, LogoIcon = tsc.Icon, tsc.style1, tsc.style2, t.Desc, m.firstName, m.lastName }) .ToList(); return set;
anchor at Stack Overflow Visit the source
Related Q & A:
- If the Lie algebra is a direct sum, then the Lie group is a direct product?Best solution by Mathematics
- If you were to start using a Wordpress framework today, which one would you use?Best solution by WordPress
- Is Oracle NOW fully supported by .NET entity framework?Best solution by Stack Overflow
- How to make Entity Framework migrations work?Best solution by Stack Overflow
- What are different types of Entities in Entity Framework?Best solution by entityframeworktutorial.net
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.