LINQ LEFT OUTER JOIN, WHERE & MIN/MAX/Count difficulty?

After the join you have access to s (the current structure) and sa the group of activities for that Structure_ID After DefaultIfEmpty() you have access to the same s and now allStructs which would correspond exactly with m in your original SQL example. You'll never get a single variable that represents all columns in both tables, but you don't get that in SQL either I believe LINQ to SQL is smart enough to translate grouping on a composite key, in which case this is what you probably want: var query = from s in db. Structures join a in db.

Activities on s. Structure_ID equals a. Structure_ID into sa from m in sa.DefaultIfEmpty() // LEFT OUTER JOIN where s.

PARK == 'Elwood' && m. CONTRACT_NO! = '' orderby s.

Structure_ID group m by new { s. Structure_ID, s. Title, s.

Photo } into g select new { myID = g.Key. Structure_ID, myDesc = g.Key. Title, myPhoto = g.Key.

Photo, myStartDate = g. Min(c => c. START_DATE), myEndDate = g.

Max(c => c. FINISH_DATE) } Note that I switched allStructs to m for consistency with your SQL, and switched group by to use m instead of s The m values are what will be contained in g s groups, with Key representing the tuple of Structure_ID Title and Photo For debugging, your best best is to turn on some logging ( DataContext. Log property) to see what SQL is being generated.

You can also use SQL profiler. It sometimes helps to work things out logically with in-memory collections and LINQ to Objects, with the caveat that you can achieve things in-memory that don't translate at all to SQL.

After the join you have access to s (the current structure) and sa, the group of activities for that Structure_ID. After DefaultIfEmpty() you have access to the same s and now allStructs which would correspond exactly with m in your original SQL example. You'll never get a single variable that represents all columns in both tables, but you don't get that in SQL either.

I believe LINQ to SQL is smart enough to translate grouping on a composite key, in which case this is what you probably want: var query = from s in db. Structures join a in db. Activities on s.

Structure_ID equals a. Structure_ID into sa from m in sa.DefaultIfEmpty() // LEFT OUTER JOIN where s. PARK == 'Elwood' && m.

CONTRACT_NO! = '' orderby s. Structure_ID group m by new { s.

Structure_ID, s. Title, s. Photo } into g select new { myID = g.Key.

Structure_ID, myDesc = g.Key. Title, myPhoto = g.Key. Photo, myStartDate = g.

Min(c => c. START_DATE), myEndDate = g. Max(c => c.

FINISH_DATE) }; Note that I switched allStructs to m for consistency with your SQL, and switched group by to use m instead of s. The m values are what will be contained in g's groups, with Key representing the tuple of Structure_ID, Title and Photo. For debugging, your best best is to turn on some logging (DataContext.

Log property) to see what SQL is being generated. You can also use SQL profiler. It sometimes helps to work things out logically with in-memory collections and LINQ to Objects, with the caveat that you can achieve things in-memory that don't translate at all to SQL.

Thanks VERY much for the help and clarifications on this. I'd never seen that 'group m by new' command before and that was the missing piece for me. Best wishes... :-) – XebraTech May 25 at 1:06.

To answer your second question I think you can do the following: myDesc = g.First(). Title myPhoto = g.First().Photo.

Thanks for this. I've tried this in a couple of places testing to see how it worked and it does get the info as you described! Best wishes... :-) – XebraTech May 25 at 1:07.

(I realize that this might be asking much here.) I'm currently just using the Console to see things after the expression is set in motion such as doing a query.Count() or something like that.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions