linq to sql查询问题

【Help】 2013-06-25 09:36:35

using (Database.db.DataContext trading = new Database.db.DataContext(da.Connetion))
{
List<game> game = (from f in db.table
join g in db.Game
on f.Code equals g.Code
where f.name == Name
orderby f.Score descending
// group f by f.Code into gname
select new game
{
Name = g.Name,
Code = g.Code
}).Take(5).ToList<game>();

return game;
}

那里加了group后,就点不出来对象了,大神帮忙看看哪里写的有问题?
...全文
102 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
【Help】 2013-06-25
  • 打赏
  • 举报
回复
引用 4 楼 q107770540 的回复:
using (Database.db.DataContext trading = new Database.db.DataContext(da.Connetion))
            {
                List<game> game = (from f in db.table
                                       join g in db.Game
                                       on f.Code equals g.Code
                                       where f.name == Name 
                                       orderby f.Score descending
                                        group f by f.Code into gname
                                        select new game
                                        {
                                            Name = gname.First().Name,
                                            Code = gname.Key
                                        }).Take(5).ToList<game>();
   
                return game;
            }
非常感谢
q107770540 2013-06-25
  • 打赏
  • 举报
回复
using (Database.db.DataContext trading = new Database.db.DataContext(da.Connetion))
            {
                List<game> game = (from f in db.table
                                       join g in db.Game
                                       on f.Code equals g.Code
                                       where f.name == Name 
                                       orderby f.Score descending
                                        group f by f.Code into gname
                                        select new game
                                        {
                                            Name = gname.First().Name,
                                            Code = gname.Key
                                        }).Take(5).ToList<game>();
   
                return game;
            }
q107770540 2013-06-25
  • 打赏
  • 举报
回复
using (Database.db.DataContext trading = new Database.db.DataContext(da.Connetion))
            {
                List<game> game = (from f in db.table
                                       join g in db.Game
                                       on f.Code equals g.Code
                                       where f.name == Name 
                                       orderby f.Score descending
                                        group f by f.Code  into gname
                                        select new game
                                        {
                                            Name = g.First().Name,
                                            Code = g.Key
                                        }).Take(5).ToList<game>();
  
                return game;
            }
【Help】 2013-06-25
  • 打赏
  • 举报
回复

using (Database.db.DataContext trading = new Database.db.DataContext(da.Connetion))
            {
                List<game> game = (from f in db.table
                                       join g in db.Game
                                       on f.Code equals g.Code
                                       where f.name == Name 
                                       orderby f.Score descending
                                       // group f by f.Code  into gname
                                        select new game
                                        {
                                            Name = g.Name,
                                            Code = g.Code
                                        }).Take(5).ToList<game>();
 
                return game;
            }
注释那块有问题
【Help】 2013-06-25
  • 打赏
  • 举报
回复

using (Database.db.DataContext trading = new Database.db.DataContext(da.Connetion))
            {
                List<game> game = (from f in db.table
                                       join g in db.Game
                                       on f.Code equals g.Code
                                       where f.name == Name 
                                       orderby f.Score descending
                                       <span style="color: #FF0000;">group f by f.Code  into gname</span> 
                                        select new game
                                        {
                                            Name = g.Name,
                                            Code = g.Code
                                        }).Take(5).ToList<game>();
 
                return game;
            }

LINQ is the part of the .NET Framework that provides a generic approach to querying data from different data sources. It has quickly become the next must-have skill for .NET developers. Pro LINQ: Language Integrated Query in C# 2010 is all about code. Literally, this book starts with code and ends with code. Most books show the simplest examples of how to use a method, but they so rarely show how to use the more complex prototypes. This book is different. Demonstrating the overwhelming majority of LINQ operators and prototypes, it is a veritable treasury of LINQ examples. Rather than obscure the relevant LINQ principles in code examples by focusing on a demonstration application you have no interest in writing, this book cuts right to the chase of each LINQ operator, method, or class. However, where complexity is necessary to truly demonstrate an issue, the examples are right there in the thick of it. For example, code samples demonstrating how to handle concurrency conflicts actually create concurrency conflicts so you can step through the code and see them unfold. Face it, most technical books, while informative, are dull. LINQ need not be dull. Written with a sense of humor, this book will attempt to entertain you on your journey through the wonderland of LINQ and C# 2010. What you’ll learn How to query Databases with LINQ to SQL, write your own entity classes, and understand how to handle concurrency conflicts. * How to leverage all the new LINQ relevant C# 2008 language features including extension methods, lambda expressions, anonymous data types, and partial methods. * How to use LINQ to Objects to query in-memory data collections such as arrays, ArrayLists, and Lists to retrieve the data you want. * Why some queries are deferred, how a deferred query can bite you, and how you can make deferred queries work for you. * How to use LINQ to XML to revolutionize your creation, manipulation, and searching of XML data. * How to query DataSets with LINQ to DataSet so you can coexist with legacy code and use LINQ to query databases other than SQL Server. Who is this book for? Apress, 2010 This book is written for the proficient C# developer, but you do not need to be up on all the latest C# features to understand the material. When you finish this book, you will have a much greater understanding of the latest C# features. amazon link:http://www.amazon.com/exec/obidos/ASIN/1430226536/buythisbooks-20

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧