select * from EFInquiry where id in(select max(Id) from dbo.EFInquiry group by ContactId)
这个可以分成两步写.
1.括号里面那一句这样写.分类求最大值.
var ids = from b in EFInquiry
group b by b.ContactId into g
select g.Max(a=>a.Id);
2.然后是求最后结果的.
var result = from item in EFInquiry
where ids.Contains(item.Id)
select item;