LINQ to remove duplicated property
Posted
by Shawn Mclean
on Stack Overflow
See other posts from Stack Overflow
or by Shawn Mclean
Published on 2010-04-06T00:39:42Z
Indexed on
2010/04/06
0:43 UTC
Read the original article
Hit count: 405
LINQ
I have a LINQ statement like this:
var media = (from p in postService.GetMedia(postId)
select new
{
PostId = postId,
SynthId = p.SynthId
});
There are many(possibly thousands) of records returned with the same SynthId. I want to select one one, any random one. So when I'm finished, media should contain records with distinct SynthId.
SynthId can be null, I want all nulls to be in media (the distinct should not affect them). My DAL is EntityFramework, if that will help.
How do I accomplish this in the most efficient way?
© Stack Overflow or respective owner