Linq查询,在单个字段上返回distinct&;返回数据子集
我有一个Linq查询,它返回三个数据元素Linq查询,在单个字段上返回distinct&;返回数据子集,linq,Linq,我有一个Linq查询,它返回三个数据元素 var billingDateResults = from s in Subscriptions .Where(s => (s.ProductCode.Contains("myCode"))) select { g.ID, BillingDate =s.BILL_THRU, s.ProductCode}; 我想对此进行不同类型的查询,以将结果限制为每个ID一条记录 var billingDateResults
var billingDateResults = from s in Subscriptions
.Where(s => (s.ProductCode.Contains("myCode")))
select { g.ID, BillingDate =s.BILL_THRU, s.ProductCode};
我想对此进行不同类型的查询,以将结果限制为每个ID一条记录
var billingDateResults = from s in Subscriptions
.Where(s => (s.ProductCode.Contains("myCode")))
group s by s.ID into g
select g.FirstOrDefault();
这是可行的,但现在返回记录中的所有字段,我想通过将结果限制在第一个示例中的3个字段来最小化数据量
做这件事的好方法是什么
TIA然后按这三个字段分组
var billingDateResults =
from s in Subscriptions
where s.ProductCode.Contains("myCode")
group new
{
g.ID,
BillingDate = s.BILL_THRU,
s.ProductCode
} by s.ID into g
select g.First(); // FirstOrDefault is not necessary, the groups will be non-empty