I have the following scenario which can solved on the database level or the Linq to EF level:
Here is my view in the database:
id title date weight
==================================
1 t1 2013-01-18 1.5
1 t1 2013-01-17 1.4
1 t1 2013-01-15 1.31
1 t1 2013-01-12 1.22
2 t2 2013-01-19 2.3
2 t2 2013-01-16 2.1
2 t2 2013-01-07 1.81
2 t2 2013-01-19 1.62
What I need as a result is one record from each item (t1 and t2) which is the newest one by date.
So the output will be like this:
id title date weight
==================================
1 t1 2013-01-18 1.5
2 t2 2013-01-19 2.3
As I said above Answers on the database level or the linq level using (Distinct) are both welcomed.
Part of my c# linq:
mylist = (from a in db.myview
join art in db.viewTags on a.id equals art.ArticleID
where (art.TagID == tag.ID)
select a).Distinct().Take(10).ToList();
I need distinct records from myview according to a.id (id field of the view)
Thanks
EDIT – as per update you want distinct by id
Full article : DistinctBy in Linq (Find Distinct object by Property)
Following is part of MoreLINQ library.
Use
DistinctByfunctionSo to find the distinct values using just the
Idproperty, you could use: