If you want to return a set of records, try this:
string sMid = "23065";
var re = DB.tblVeh
.Where(v=>v.MID.Equals(sMid) && v.Name != string.Empty)
.GroupBy(v=>v.Name)
.Select(g=> new
{
Vname = g.Key.Name,
Count = g.Count()
}).ToList();
Above code returns:
Vname Count
d1 2
e3 5
g2 8
To be able to go through the resultset, you have to use
foreach(...)
loop:
Console.WriteLine("Vname - Count");
foreach(var a in re)
{
Console.WriteLine("{0} - {1}", a.Vname, a.Count);
}
If you want to return string splited by comma, try this:
string sMid = "23065";
var re1 = String.Join(",", DB.tblVeh
.Where(v=>v.MID.Equals(sMid) && v.Name != string.Empty)
.GroupBy(v=>v.Name)
.Select(g=> new
{
a = String.Format("[{0},{1}]", g.Key.Name, g.Count())
}));
Above code returns:
[d1,2],[e3,5],[g2,8]