• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 533
  • Last Modified:

Need LINQ Lambda Entity Frameworks

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

   ClientApp INNER JOIN App ON ClientApp.AppId = App.AppId

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();


Charles Baldo
Charles Baldo
  • 2
1 Solution
Fernando SotoRetiredCommented:
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)
	                                 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

Charles BaldoSoftware DeveloperAuthor Commented:
Thank you kindly
Fernando SotoRetiredCommented:
Not a problem Charles, glad to help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now