[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Need LINQ Lambda Entity Frameworks

Posted on 2014-02-15
3
Medium Priority
?
523 Views
Last Modified: 2016-02-10
I am new to LINQ and Entity Frameworks.  I am trying to figure out how to do a join in LINQ and return data in a list.  I am using REST webservices.

I have the following  SQL that returns 18 rows

SELECT
   ClientApp.ClientId,
   ClientApp.AppId,
   ClientApp.ClientAppExpirationDate,
   App.Description
FROM
   ClientApp INNER JOIN App ON ClientApp.AppId = App.AppId
where
   ClientApp.ClientId=1

-----------------------------------
With the help of a colleague I have the following Lambda LINQ that returns the same number of rows in two lists the dates and descriptions match in the same rows. Only problem is I need one list.  Short of creating a third list and going through and putting the data in the row from each list into the new list I am hoping a single LINQ query with the same join can do the job.

using (var context = new  WSContext())
{
//   List<AppList> appList = new List<AppList>();
List<ClientApp> clientAppList = new List<ClientApp>();
List<App> appList = new List<App>();
var app = context.ClientApps.Where(c => c.ClientId == _clientID).Join(context.Apps, ca => ca.AppId, a => a.AppId, (ca, a) =>
      new { clientApp = ca, apps = a });
var resultApps = app.Select(s => s.apps);
var resultClientApp = app.Select(a => a.clientApp );

clientAppList = resultClientApp.ToList();
appList = resultApps.ToList();

-----------------------

}
0
Comment
Question by:Charles Baldo
[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
  • 2
3 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 39862238
Hi charlesbaldo;

You were not that far off. This code should do what you need.

using (var context = new  WSContext())
{
	   var resultList = context.ClientApp
	                           .Where(c => c.ClientId == _clientID)
	                           .Join(context.Apps, 
	                                 ca => ca.AppId, 
	                                 a => a.AppId, 
	                                 (ca, a) =>  new 
	                                     { 
	                                         ClientId = ca.ClientId,
	                                         AppId = caa.AppId,
	                                         ClientAppExpirationDate = ca.ClientAppExpirationDate,
	                                         Description = a.Description	                                         
	                                     }
	                                 );
}

Open in new window

0
 

Author Closing Comment

by:Charles Baldo
ID: 39862273
Thank you kindly
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 39862752
Not a problem Charles, glad to help.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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