大家好,小弟一个linq的有关问题请问一下大家
大家好,小弟一个linq的问题请教一下大家
如下图
通过linq我怎么查出_newsource为新浪科技的条目呢?
这些item都在SampleDataSource.AllNewsGroups这个数据集合里
麻烦大家了~~
------解决方案--------------------
DataTable dt = new DataTable();
var a = from t in dt.AsEnumerable()
where t.Field<string>("isindoor") == "新浪科技"
orderby t.Field<decimal>("utility_rate")
select t;
------解决方案--------------------
------解决方案--------------------
var query=SampleDataSource.AllNewsGroups.Items.Where(x=>x._newsource=="新浪科技");
------解决方案--------------------
SampleDataSource.AllNewsGroups.SelectMany(x => x.Where(y => y._newsource == "新浪科技")));
如下图
通过linq我怎么查出_newsource为新浪科技的条目呢?
这些item都在SampleDataSource.AllNewsGroups这个数据集合里
麻烦大家了~~
LINQ
.net
------解决方案--------------------
DataTable dt = new DataTable();
var a = from t in dt.AsEnumerable()
where t.Field<string>("isindoor") == "新浪科技"
orderby t.Field<decimal>("utility_rate")
select t;
------解决方案--------------------
List<AllNewsGroups> AllNewsGroups = new List<AllNewsGroups>();
List<AllNewsGroups2> AllNewsGroups2 = new List<ceshi.AllNewsGroups2>();
AllNewsGroups2.Add(new AllNewsGroups2 { Name = "新浪科技" });
AllNewsGroups2.Add(new AllNewsGroups2 { Name = "新浪科技" });
AllNewsGroups2.Add(new AllNewsGroups2 { Name = "新浪科技" });
AllNewsGroups2.Add(new AllNewsGroups2 { Name = "新浪科技" });
AllNewsGroups.Add(new AllNewsGroups { Name = "1",AllNewsGroups2 = AllNewsGroups2 });
AllNewsGroups.Select(m => (m.AllNewsGroups2.Where(t => t.Name == "新浪科技")).Count()>0);
public class AllNewsGroups
{
public string Name{get;set;}
public List<AllNewsGroups2> AllNewsGroups2 { get; set; }
}
public class AllNewsGroups2
{
public string Name { get; set; }
}
------解决方案--------------------
var query=SampleDataSource.AllNewsGroups.Items.Where(x=>x._newsource=="新浪科技");
------解决方案--------------------
SampleDataSource.AllNewsGroups.SelectMany(x => x.Where(y => y._newsource == "新浪科技")));