1

I have two lists: Owners and Permits. They match on OwnerID, and come from two database tables of the same name

I have a ViewModel: ViewModel, which holds a list of Owners and a list of Permits

I have this select statement which selects all owners and every permit associated with that owner:

var list = from o in owners
join p in permits
on o.LandOwnerID equals p.Landowner into tbl
from p in tbl.ToList()
where o.RecordDeleted == false
orderby o.ModifiedDate descending
select new ViewModel
{
    Owner = o,
    Permit = p
};

With this query, my results look like this:

Owner1     Permit1
Owner1     Permit2
Owner1     Permit3
Owner2     Permit4
Owner3     Permit5
Owner3     Permit6
Owner3     Permit7

What I would like to end up with is this:

Owner1     Permit1
Owner2     Permit4
Owner3     Permit5

If this were in a SQL query, I would do a groupby, an orderby, and a select top 1 permit.

How do I do this when comparing two lists? The groupby option doesn't exist. -- clarification: there is no GroupBy in my autocomplete options when I try adding it anywhere within the query.

Carthax
  • 119
  • 1
  • 12

0 Answers0