zoukankan      html  css  js  c++  java
  • 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的能力。

  • 相关阅读:
    UIScrollView(滚动视图)
    NSJSONSerialization(json序列化)
    手势(UIGestureRecognizer)
    mac常用命令
    ios设备相关
    UITextField
    cocos2d学习笔记
    NSTimer(定时器)
    git命令
    Java 线程的终止-interrupt
  • 原文地址:https://www.cnblogs.com/2018/p/1882549.html
Copyright © 2011-2022 走看看