user6408005 user6408005 - 6 months ago 25
SQL Question

sql to linq query convert

I try to convert

SQL
to
LINK
query

I try this

SQL
query

Select name, count(*) from tblVehicles
WHERE MID = 23065 and name<> '' Group By name


LINQ
query

var re = (from vehvoila in DB.tblVehicles
where vehvoila.MID='23065' && vehvoila.name
group vehvoila by new{vehvoila.name} into g
select new
{
g.Key.name,
cnt=g.Select(t=>t.name).Count()
});


How I use <> in
LINQ
?

Answer

What could work for you is

where vehvoila.MID == "23065" && !(vehvoila.name == null || vehvoila.name == "")

or just

where vehvoila.MID == "23065" && vehvoila.name != ""

String.IsNullOrEmpty in not supported in Linq-SQL:

Method 'Boolean IsNullOrEmpty(System.String)' has no supported translation to SQL.