基于多列的DISTINCT

时间:2019-02-11 01:35:44

标签: c# linq microsoft-dynamics dynamics-365

我在linq中有一个groupby,看起来像这样:

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

我需要返回的所有实体都是不同的,我该怎么做?!

0 个答案:

没有答案