c# - Using linq to group a table that contains substrings -
c# - Using linq to group a table that contains substrings -
my info table(deviceinfo):
id | os | device ----------------------------------------------- 1 | android 2.2 | samsung 2 | linux/android 4.2 | lg 3 | linux/android 4.4.2 | htc 4 | android 3.2 | samsung 5 | android 3.0 | motorola 6 | ios 7.1.2 | ipad 7 | ios 8.0 | iphone 6 8 | ios 6.1.6 | iphone 4i want grouping table android , ios user using linq.actually have grouping table using substring "android" , "ios". output should be
id | user | count ---------------------------- 1 | android | 5 2 | ios | 3how able table using linq?
you can seek :
// db datacontext var groupbyos = (from c in (from d in db.deviceinfo d.os.toupper().contains("android") || d.os.toupper().contains("ios") grouping d new { d.os } dev select new { user = dev.key.os.toupper().contains("android") ? "android" : "ios", devicecount = dev.count() }) grouping c new { c.user } newgrp select new { newgrp.key.user, count = newgrp.sum(q => q.devicecount) }).tolist();
c# sql linq group-by
Comments
Post a Comment