We know that LINQ to SharePoint actually eventually turns into calm to access SharePoint, so how do we know what the calm statement we write the query statement will ultimately look like. We can use the following methods to achieve our goal.1. Start by creating a new class named Camldebug in our SharePoint project:The CALMDebug.cs code is as follows:Using System;Using System.Collections.Generic;Using System.Linq;Using System.Text;Using System.IO;Using
LINQ Learning Series ----- 1.3 extension method, linq ----- 1.3
This article continues with the source code of yesterday's Lambda expression. Yesterday I spoke about Lambda expressions. This article describes the extension methods. These two points are new features of Linq.
1. Introduction to extension methods
If you don't talk nonsense, go to the source code fir
Label: style blog color Io ar strong SP Div on
The set operator operates on the set or sequence set of elements and returns a set. There are four collection query operators in LINQ: distinct, union, intersect, and except T.
1. Distinct
The distinct operator deletes duplicate values in a set and returns distinct elements in the set.
1>. Prototype Definition
public static IQueryable
public static IQueryable
2>. Example
int[] fibonacci = new int[] { 1, 1
Label: style blog color AR for strong SP Div on Concatenation is a process of connecting two objects. In LINQ, concatenation combines two sets into one, which is implemented through the Concat operator. Concat 1>. Prototype Definition Public StaticIqueryable ThisIqueryable source ); Public StaticIqueryable ThisIqueryable 2>. Example VaRExpr =Context. categories. Select (C=>C. categoryname). Concat (context. Products. Select (P=>P. productname )
The quantifiers operator returns a Boolean value indicating whether some or all element symbols in the sequence specify conditions. In LINQ, quantifiers include all, any, and contains.
1. All
The all operator determines whether all values in the Set meet the specified conditions. The returned value is a Boolean value. If all values meet the conditions, true is returned; otherwise, false is returned.
1>. Prototype Definition
Public static bool all
Comprehensive Writing of Linq and comprehensive Writing of linq
Var queryCount = (from pv in db. ProvinceJoin pc in (from cc in(From v in db. ERPStockProductTriggerJoin s in db. Storage on v. StorageID equals s. StorageIDJoin B in db. BranchSet on s. BranchSetID equals B. IdJoin p in db. Product on v. ProductID equals p. IdJoin c in db. PriceProfile. Where (w => w. Type = 1) on p. Id equals c. ProductIDWhe
LINQ to datasets require the use of System.Core.dll, System.Data.dll and System.Data.DataSetExtensions.dll, add references System.Data and System.Data.DataSetExtensions to the project.1. DataTable Read ListDataSet ds = new DataSet ();//Omit the DS's fill code datatable products = ds. tables["Product"];ienumerableDataSet ds = new DataSet ();//Omit the DS's fill code datatable products = ds. tables["Product"];var rows = products. AsEnumerable () . Se
) { Console.WriteLine (Eachchar);}The above code first selects the person with the FirstName as "Sccot" and returns its LastName with SelectMany. Note that the result of the LastName type is String,selectmany is to expand the string to a list of char types.The SelectMany also has additional overloads. For example, if we want to display fullname and corresponding phonenumber at the same time, we can use the following code to achieve the goal:ListPerson.getallperson ();varresult = Personinlist.
Evolution Process (delegate => Lamb => Linq)
1.
Func Return s. Length = 5 ;};
Func Return s ;}
Func Return s. ToUpper ();}
IEnumerable . Where (filter)
. Orderby (extract)
. Select (project );
2.
IEnumerable . Where (s => s. Length = 5)
. Orderby (s => s)
. Select (s => s. ToUpper ())
3.
IEnumerable Where s. Length = 5
Orderby s
Select s. ToUpper ();
Understanding the evolution of Code helps to have a preliminary understanding of
We will continue to explain the LINQ statements. In this article, we will discuss Union all/Union/intersect operations, top/bottom operations, paging operations, and sqlmethods operations. Union all/Union/intersect operation
Applicable scenarios: process two sets, such as append, merge, take the same item, intersection item, and so on. Concat (connection)
Note: different sets are connected, and the same items are not automatically filtered; latency.
The equal operator compares two sequences to check whether their corresponding elements are the same. If the two sequences have the same elements and their values are the same, the two sequences are considered equal.The sequenceequal operator determines whether two sets are equal. The determination is done by enumerating two data sources in parallel and comparing the corresponding elements. The return value is a Boolean value. If the two sets are equal, true is returned. Otherwise, false is retu
To enable LINQ to be seamless and integrated with the C # language, Microsoft has added new features to c#3.0, which focuses on enhancing LINQ-related.
1, the VAR keyword, collection initialization, and anonymous types
2. LAMBDA expression
3. Partial (Partial) method
4. Extension method
5. Expression tree
1, the VAR keyword, collection initialization, and anonymous types
Var:
You can give local vari
Label: = new Northwindcontext ())
{
var= context. Products;
foreach (var in expr)
{
Console.WriteLine (item. ProductName);
}
} SELECT
[Extent1].[ProductID] as [ProductID],
[Extent1].[CategoryID] as [CategoryID],
[Extent1].[ProductName] as [ProductName],
[Extent1].[UnitPrice] as [UnitPrice],
[Extent1].[discontinued] as [discontinued]
from [dbo].[Product] as [Extent1] 2. Querying a specified field var = context. Products
. Select =
I read the LINQ written by Li yongjing. I tried it once. Now, only the tested ones are recorded.
Group by/having Operator
VaR q =
From P in db. Products
Group P by P. categoryid into G
Select g;
Some people will say having. Actually, I don't know how to use it. Failed after several attempts.
Maximum Value
Note: first, sort by categoryid to determine the products with the largest unit price in each product category. Take out the categoryid value and as
LINQ to SQLBy default, a transaction is created when an update is submitted. If some modifications are incorrect, other modifications will not take effect.
Insert2Data in tables for Transaction Processing
Private Void Transadd (){Dataclasses1datacontext DB = New Dataclasses1datacontext (sqlconstr ); If (Db. connection! = Null ) DB. Connection. open ();Dbtransaction TRAN = dB. Connection. begintransaction ();DB. Transaction = Tran; Try {Studen
1. Takevar expr = context. Products . Take (ten);var expr = ( from in context. Products select p) . Take (ten);SELECT TOP(Ten) [C].[ProductID] as [ProductID], [C].[CategoryID] as [CategoryID], [C].[ProductName] as [ProductName], [C].[UnitPrice] as [UnitPrice], [C].[UnitsInStock] as [UnitsInStock], [C].[discontinued] as [discontinued] from [dbo].[Product] as [C]2. Skip Before you can use the Skip method, you need to sort by order first
LINQ via C #
Recently I am giving a series of talk on LINQ. the name "LINQ via C #" is copied from "CLR via C #", one of my favorite books. currently Part 1-8 are finished, and the entire series shocould be 10 parts. the contents are: introducing LINQ what is LINQLINQ via C # events posters Design
10
LINQ (Language integrated Query) is a leading figure in Visual Studio 2008. With the help of LINQ technology, we can query any form of data using a SQL-like syntax. The data sources that LINQ supports so far have SQL Server, XML, and data collections in memory. Developers can also use the extended framework provided by them to add more data sources, such as
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.