简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM