score:3
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)
.distinct()
.count();
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.
score:2
you can use linqpad to convert to linq and lambda expressions
score:3
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 ,country=p.country}).distinct();
Source: stackoverflow.com
Related Query
- How to get SQL query into LINQ form in C# code
- How to get text from LINQ to SQL query into a TextBox?
- How can I convert this SQL Query into LINQ (OVER (PARTITION BY Date))
- How do I get this Linq query with custom join into a DataSet?
- How is this Nested Set SQL query converted into a LINQ query?
- How to convert this complex SQL Query with Subqueries into LINQ
- How can I code numerous MIN functions into one LINQ to DataSet query
- How can i get sql query Equivalent to a linq expression
- How to make this SQL query into DotNet Core 2.1 Linq
- How to convert sql inner join query into linq to sql query and convert into list
- What SQL query or LINQ code would get the following data?
- How do I convert this SQL inner join query into LINQ syntax?
- How to make this simple SQL query into a Linq Statement?
- How to get multiple column value from database into a list using LINQ query
- How to convert Sql Datetime query into Linq
- How to convert data from two tables get from Linq query to List witch can be populated in wpf form
- how to translate a linq expression into sql string use c# code
- How to Convert SQL query to LINQ (to get last record each bookingStatus)
- C# How to convert SQL into a LINQ query
- How to convert this sql query into linq query. I am stuck at the group by and sum part
- How to convert sql query into Linq to entities?
- How to convert this query string into LINQ to SQL query?
- How to change SQL query into Linq
- how to convert a sql query into linq LEFT OUTER JOIN
- How to convert SQL Query into LinQ
- How to use one Column of Sql query into another sql query inside C# Code
- How can i convert a SQL query into LINQ using group and having?
- How to replicate in LINQ a SQL query that uses Coalesce to pivot rows into a single column
- How are people unit testing code that uses Linq to SQL
- How To Project a Line Number Into Linq Query Results
More Query from same tag
- Using Linq.Dynamic where method with a dynamic list gives error
- LinqKit nested invoke "LINQ to Entities does not recognize the method 'Invoke'"
- Adding an element to an array
- max and min rates for the particular area -lambda query
- How can I use the MYSQL BIT_COUNT function through nhibernate/fluent nHibernate?
- How to rewrite this linq query correctly?
- Generic LINQ extension for calculating weighted average in Visual Basic 2010
- Traverse a Linq Expression to set the value of a property field
- Doubts about how to read XML with Linq
- C# Expression using And Or and Not expression together based on AST
- Is there a C# function that checks if a list is empty and doesn't count null as an element?
- linq.sum is rounding
- LiNQ using ThenBy after OrderBy
- Need to debug LINQ simple queries in Visual Studio 2010
- How do I solve server side pagination issue in JQGrid using mvc4
- What's wrong with this linq query?
- asp.netHow to edit header text in Gridview while joining tables
- Calling generic method with a type argument known only at execution time
- Linq query error
- Group and join give missing field
- SkipWhile TakeWhile, then take also lines above until a match
- Getting all of the values for a property for a list of objects
- Can LINQ To SQL generate invalid SQL?
- Union-ing two custom classes returns duplicates
- Using a native SQL Server function in Nhibernate?
- Linq Query with date range not returning any records?
- IndexOutOfRangeException was unhandled by user code
- Two possible programming patterns, which one is more appropriate?
- How to search in a list whether a list of given items exists in the same order
- Linq with reflexion error: Expression LINQ 'Invoke' node is not supported in LINQ to Entities