0

i am bit confused by the nature and working of query , I tried to access database which contains each name more than once having same EMPid so when i accessed it in my DROP DOWN LIST then same repetition was in there too so i tried to remove repetition by putting DISTINCT in query but that didn't work but later i modified it another way and that worked but WHY THAT WORKED, I DON'T UNDERSTAND ?

QUERY THAT DIDN'T WORK

var names = (from n in DataContext.EmployeeAtds select n).Distinct();
QUERY THAT WORKED of which i don't know how ?

var names = (from n in DataContext.EmployeeAtds select new {n.EmplID, n.EmplName}).Distinct();
why 2nd worked exactly like i wanted (picking each name 1 time)

i'm using mvc 3 and linq to sql and i am newbie.

3
Contributors
2
Replies
11
Views
3 Years
Discussion Span
Last Post by Manish02
1

why 2nd worked exactly like i wanted

Because there you select just two fields, in the first you select an entire record.

0

in first query you have selected entire records and in second query only emp id and emp name

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.