Suppose that I have a table with a column labeled Name, which contains (possibly) repeating entries of unique usernames. What LINQ-to-SQL statement can I write to uniquely traverse the usernames? In other words:
Here is an example of the table:
Name Log
User1 05/13/13
User2 05/13/13
User2 05/14/13
User3 05/15/13
User1 05/15/13
I want to select usernames uniquely:
User1, User2, User3.
Thanks in advance!
SELECT DISTINCT NAME FROM TABLE;
or in LinQ;
var names = Table.Select( t => t.Name ).Distinct().ToList();
Create a linq query and use the .Distinct extension method on the result.
Example:
var users = (from logfile in logfiles select logfile.Name).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