linq,问Tim和懂的人,顶者有分!!!!
今天看这个帖子
http://topic.csdn.net/u/20101025/18/3f583705-38f8-4abe-b778-9faa6cc52bee.html
发现fangxinggood的写法不是很懂,代码入下
其中这里
var query =
from u in list
where u.IsNormal == "1"
group u by u.UserId into g
orderby g.Key
from u2 in g
where u2.Date == g.Min(u3 => u3.Date)
select u2;
list通过userid分组后并入g,下面u2应该是g的分组成员,怎么能得到Date这个属性呢?
我分开写的话,这样
var q = from u in list
where u.IsNormal == "1"
group u by u.UserId into g
orderby g.Key select g;
var w = from u2 in q
where u2.Date == q.Min(u3 => u3.Date)
select u2;
根本就不行。请问这是怎么回事。
这是一。
第二:有多个from这种情况
比如var g = from u in list
from u1 in list
select u;
我查看结果,他们似乎做的是笛卡尔积,不太好用,实际中怎么用呢?
第三:如果我是linq to entities这种情况,我怎么查看当前linq对应的sql呢?还是根本看不了?!
赶快来人!!
http://topic.csdn.net/u/20101025/18/3f583705-38f8-4abe-b778-9faa6cc52bee.html
发现fangxinggood的写法不是很懂,代码入下
static void Main(string[] args)
{
var list = GetData();
var query =
from u in list
where u.IsNormal == "1"
group u by u.UserId into g
orderby g.Key
from u2 in g
where u2.Date == g.Min(u3 => u3.Date)
select u2;
foreach (var u in query)
Console.WriteLine("{0}, {1}, {2}", u.UserId, u.Date, u.Rank);
Console.Read();
}
static IEnumerable<User> GetData()
{
yield return new User { UserId = "100", Rank = "10", Date = "20101012", IsNormal = "1" };
yield return new User { UserId = "100", Rank = "20", Date = "20101009", IsNormal = "1" };
yield return new User { UserId = "200", Rank = "11", Date = "20101011", IsNormal = "1" };
yield return new User { UserId = "100", Rank = "18", Date = "20101008", IsNormal = "1" };
yield return new User { UserId = "300", Rank = "2", Date = "20101010", IsNormal = "1" };
yield return new User { UserId = "300", Rank = "15", Date = "20101013", IsNormal = "1" };
yield return new User { UserId = "300", Rank = "16", Date = "20101002", IsNormal = "0" };
}
其中这里
var query =
from u in list
where u.IsNormal == "1"
group u by u.UserId into g
orderby g.Key
from u2 in g
where u2.Date == g.Min(u3 => u3.Date)
select u2;
list通过userid分组后并入g,下面u2应该是g的分组成员,怎么能得到Date这个属性呢?
我分开写的话,这样
var q = from u in list
where u.IsNormal == "1"
group u by u.UserId into g
orderby g.Key select g;
var w = from u2 in q
where u2.Date == q.Min(u3 => u3.Date)
select u2;
根本就不行。请问这是怎么回事。
这是一。
第二:有多个from这种情况
比如var g = from u in list
from u1 in list
select u;
我查看结果,他们似乎做的是笛卡尔积,不太好用,实际中怎么用呢?
第三:如果我是linq to entities这种情况,我怎么查看当前linq对应的sql呢?还是根本看不了?!
赶快来人!!
...全文
相关推荐
[Pro.Visual.Studio.LightSwitch.2011.Development].Tim.Leung.文字版.pdf
- **附录B:LINQ查询操作符**:LINQ是一种强大的查询语言,这部分介绍了如何使用LINQ查询操作符来优化数据查询。
C编程大师课程项目_由TimCorey主讲涵盖C语言从基础到高级的全面学习内容包括变量声明数据类型控制结构面向对象编程异常处理多线程编程LINQ查询异步编程.zip
在现代编程技术中,LINQ(语言集成查询)是.NET平台上用于查询数据的强大功能。课程中将展示如何在C#语言中使用LINQ技术进行数据查询和操作,让学员能够处理来自不同数据源的数据。
《领域驱动设计C# 2008实现问题.设计.解决方案》.((美)Tim McCarthy) [PDF]__0525).rar
此外,作者可能还会介绍如何利用C# 2008的特性,如 LINQ 和匿名类型,来简化代码并提高可读性。
Visual Studio Lightswitch 2015 2nd 第2版 无水印pdf 0分
《Visual Studio Lightswitch 2015 第2版:轻松构建企业应用》是一本全面更新的书籍,由获奖作者Tim Leung编写,专注于指导读者如何在无需编写代码的情况下,利用Visu
《领域驱动设计C# 2008实现问题.设计.解决方案》.((美)Tim McCarthy)
根据提供的信息,《领域驱动设计C# 2008实现问题.设计.解决方案》由美国作者Tim McCarthy编写,主要探讨了如何使用C# 2008语言来实现领域驱动设计(Domain-Driven Design


