Is there way to rewrite:
var tbl = ds.TABLES; var q = from c in tbl select c.TABLE_TYPE; string s = ""; foreach (var item in q.Distinct()) { s += "[" + item + "]"; } MessageBox.Show(s);
So that the Distinct() call is in the LINQ query?
LINQ Distinct is not that smart when it comes to custom objects. All it does is look at your list and see that it has two different objects (it doesn't care that they have the same values for the member fields). One workaround is to implement the IEquatable interface as shown here.
distinct in Linq to get result based on one field of the table (so do not require a whole duplicated records from table). I know writing basic query using distinct as followed: var query = (from r in table1 orderby r. Text select r).
There is no Distinct()
method syntax in the language integrated query syntax. The closest you could do would be to move the current call:
var q = (from c in tbl select c.TABLE_TYPE).Distinct();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With