DISTINCT based on multiple columns

Refresh

1 weeks ago

Views

5 time

0

I have a groupby in linq that looks like this:

var grouped = from all in Allergies.Entities.AsEnumerable()


group (Guid)all.GetAttributeValue<AliasedValue>("allergy.new_foodsensitivityid").Value
   by new
   {
       group = all.GetAttributeValue<OptionSetValue>("new_group"),
       time = all.GetAttributeValue<OptionSetValue>("new_time"),
       desc = all.GetAttributeValue<string>("new_desc"),
       child = (Guid)all.GetAttributeValue<AliasedValue>("kid.contactid").Value,
       childName = (string)all.GetAttributeValue<AliasedValue>("kid.fullname").Value,
       item = (EntityReference)all.GetAttributeValue<AliasedValue>("item.substitutedproductid").Value,
       type = (OptionSetValue)all.GetAttributeValue<AliasedValue>("item.new_type").Value,
   } into g
   select new
   {
       g.Key.group,
       g.Key.time,
       g.Key.desc,
       g.Key.child,
       g.Key.childName,
       g.Key.item,
       g.Key.type,
       allergy = g.FirstOrDefault()
   };

I need all to be distinct but the allergy, how do I do that?!

0 answers