SUPER_USER
SUPER_USER

Reputation: 273

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 ?

Upvotes: 1

Views: 110

Answers (1)

Alex Marculescu
Alex Marculescu

Reputation: 5770

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.

Upvotes: 5

Related Questions