LINQ --- Language Integrated Query
LINQ to Objects (to APIs)
LINQ to XML
LINQ to SQL (Relational database)
New namespace System.Xml.Linq includes a series of new LINQ to XML objects that make working with xml easier:
1) XDocument instead of XmlDocument
XDocument xdoc = XDocumnet.load(@"d:\HPCTO");
query xml:
XDocument xdoc = XDocument.Load(@"D:\HPCTO\Pavilio.xml");
var query = from ConfigGroup in xdoc.Descendants("ConfigGroup")
select new
{
ProductDescription = ConfigGroup.Attribute("Description").Value
};
foreach (var item in query)
{
Response.Write(item);
Response.Write("
");
Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts
Tuesday, August 26, 2008
Thursday, May 1, 2008
disable tracking in DataContext
You can disable the tracking ability by setting ObjectTrackingEnabled to false.
Disabling object tracking also prevents you from subitting updates to the data.
Disabling object tracking also prevents you from subitting updates to the data.
Monday, April 28, 2008
How Deferred Execution Works
Query operators provide deferred execution by returning decorator sequences.
Calling where merely consts the decorator wrapper sqequence, holding a reference to the input sequence, the lambda expression and any other arguments supplied.
---- c# 3.0 In a Nutshell
When query operator acutally querying the array through the where decorator
Calling where merely consts the decorator wrapper sqequence, holding a reference to the input sequence, the lambda expression and any other arguments supplied.
---- c# 3.0 In a Nutshell
When query operator acutally querying the array through the where decorator
Friday, April 11, 2008
Debug tool --- Query Visualizer tool
Download from:
http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx
and copy SqlServerQueryVisualizer.dll paste to file://program/ Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers
restart VS 2008 , you are good to debug LINQ Expression
http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx
and copy SqlServerQueryVisualizer.dll paste to file://program/ Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers
restart VS 2008 , you are good to debug LINQ Expression
Tuesday, April 8, 2008
Iterator yield return sample code
using System.Collections.Generic;
protected void Page_Load(object sender, EventArgs e)
{
foreach (var v in OneTwoThree())
{
Response.Write(v);
}
}
private IEnumerable OneTwoThree()
{
Response.Write("return 1");
yield return 1;
Response.Write("return 2");
yield return 2;
Response.Write("return 3");
yield return 3;
}
protected void Page_Load(object sender, EventArgs e)
{
foreach (var v in OneTwoThree())
{
Response.Write(v);
}
}
private IEnumerable
{
Response.Write("return 1");
yield return 1;
Response.Write("return 2");
yield return 2;
Response.Write("return 3");
yield return 3;
}
LINQ Sample
var processes =
Process.GetProcesses().Where(process => process.WorkingSet64 > 20 * 1024 * 1024)
.OrderByDescending(process => process.WorkingSet64)
.Select(process => new { Id = process.Id, Name = process.ProcessName });
foreach (var obj in processes)
{
Response.Write(obj.Id +" & "+ obj.Name +"");
}
Process.GetProcesses().Where(process => process.WorkingSet64 > 20 * 1024 * 1024)
.OrderByDescending(process => process.WorkingSet64)
.Select(process => new { Id = process.Id, Name = process.ProcessName });
foreach (var obj in processes)
{
Response.Write(obj.Id +" & "+ obj.Name +"");
}
Anonymous types
Sample code:
var v1 = new {FirstName ="Bin", LastName="Zeng" }
The conpilers consider anonymous types that is specified within the same program with properties of the same names and types in the same order to be the same type.
Linitations:
var v1 = new {FirstName ="Bin", LastName="Zeng" }
The conpilers consider anonymous types that is specified within the same program with properties of the same names and types in the same order to be the same type.
Linitations:
Subscribe to:
Posts (Atom)