Monday

distinct linq example

1.Create IEqualityComparer class

public class DistinctTitle : IEqualityComparer<SourceType> {
public bool Equals(SourceType x, SourceType y) {
return x.title.Equals(y.title);
}

public int GetHashCode(SourceType obj) {
return obj.title.GetHashCode();
}
}

2. Comparer can be used as follows:

var x = (from t in dc.table
where t.sourceId = 5
order by t.itemId descending
select t)
.Distinct(new DistinctTitle())
.Select(t=>new{t.itemId, t.sourceId, t.title });

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...