Linq的其他方面

前面的几篇文章简述了LINQ的基本概念

Linq的概念解析

http://www.cnblogs.com/2018/archive/2010/11/12/1875850.html

LINQ 概述、语法及实例

http://www.cnblogs.com/2018/archive/2010/11/14/1877144.html

深入理解linq的参考例子

http://www.cnblogs.com/2018/archive/2010/11/16/1878675.html

 

实际使用中,linq的其他方面做个简述,以备使用中参考

Linq to Everything

微软的框架包含的:

Linq to object ; linq to xml ; linq to sql

 

Codeplex.com社区有很多的linq to ***

基于这些Provider,可以使用linq语法实现各种事情

Linq to object

对于实现了IEnumerable的对象操作,使用查询操作符和查询表达式操作

Linq to xml

特殊的部分:XmlObject XNode XElement XAttribute XText XDocument XStreamingElement等

建立XML

Books.txt

0735621632,CLR via C#,Jeffrey Richter,Microsoft Press,02-22-2006,59.99

0321127420,Patterns Of Enterprise Application Architecture,Martin Fowler,Addison-Wesley Professional,11-05-2002,54.99

 

XElement xml = new XElement("books",

        from line in File.ReadAllLines("books.txt")

        where !line.StartsWith("#")

        let items = line.Split(',')

        select new XElement("book",

                              new XElement("title", items[1]),

                                   new XElement("authors",

                                   from authorFullName in items[2].Split(';')

                                   let authorNameParts = authorFullName.Split(' ')

                                   select new XElement("author",

                                     new XElement("firstName", authorNameParts[0]),

                                          new XElement("lastName", authorNameParts[1])

                                   )

                            ),

                            new XElement("publisher", items[3]),

                            new XElement("publicationDate", items[4]),

                            new XElement("price", items[5]),

                            new XElement("isbn", items[0])

                            )

      );

 

XML处理

<?xml version="1.0" encoding="utf-8" ?>

<books>

       <book>

              <title>Linq in Action</title>

              <author>Fabrice Marguerie</author>

              <author>Steve Eichert</author>

              <publisher>Manning</publisher>

              <rating>4</rating>

       </book>

 

                     XElement books = XElement.Load("books.xml");

 

                     var manningBooks =

                                          from b in books.Elements("book")

                                          where (string) b.Element("publisher") == "Manning"

                                          orderby (string) b.Element("title")

                                          select b.Element("title"); 

linq to sql

现在一般基于Entity Framework建模形式,可视化实现更方便一些。

System.Data.Linq.DataContext

 

PLINQ

Parallel LINQ (PLINQ) is a parallel implementation of LINQ to Objects.

在现在的多核CPU上,这个很有用,可充分利用CPU的能力。

posted @   2012  阅读(383)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示