Accepted answer

i suspect you want:

var query = from entry in dbcontext.table1
            where entry.department == "abc" && entry.skillname != null
            select entry.skillname;

var count = query.distinct().count();

or using extension method syntax, in one go:

var count = dbcontext.table1
                     .where(entry => entry.department == "abc" && 
                                     entry.skillname != null)
                     .select(entry => entry.skillname)

as shown by mesiesta, you can combine query expressions with calls not supported within query expressions, but i tend to assign the query expression to an intermediate variable... i personally find it clearer, but use whichever you (and your team) prefer.


you can use linqpad to convert to linq and lambda expressions


something like this

 int count = (from p in table1
              where p.department == "abc" && p.skill_name != null
              select p.skill_name).distinct().count(); 

for second query you can use this

 var query= (from p in customer
             where p.customer_code=="1001"
             select new { location=p.location ,}).distinct();

Related Query

More Query from same tag