I have a database table that has the following records. There are more fields than what I have displayed below, but I only want to return the Owner, Brand Name, ID#, and Type fields.
Owner Ingredient BrandName ID# Type
XXX Methoprene Precor 123-333 H
XXX Permethrin Precor 123-333 H
I am trying to write an Entity Framework query to select only the distinct records in the Brand Name field, but still return the other columns in a list back to the controller to display in a partial view. The following is the code I have attempted, but I cannot seem to get the query written correctly:
return db.Pesticides
.Where(c => c.Owner == Owner && c.BrandName == PesticidesBrand)
.GroupBy(c => c.Owner, c =>c.BrandName )
.Select(d => d.FirstOrDefault())
.ToList();
I realize the Select clause is not correct, but need help getting correct syntax to return the 4 specific fields. I would like the query to return the following record:
XXX Precor 123-333 H
Thanks in advance....