Für die Erstellung einer temporären Variable innerhalb einer Query Expression kann das Schlüsselwort let verwendet werden. Mithilfe einer Formel wird an diese Variable ein neuer Wert aus bestehenden Daten zugewiesen. Die Variable ist dann innerhalb der Query Expression weiterverwendet und bei Bedarf im Select-Block ausgegeben werden. Die Lesbarkeit des Codes wird durch die Verwendung von Schlüsselwort let gesteigert und der Code bleibt übersichtlich. In dem folgenden Beispiel werden mithilfe des let-Schlüsselwortes zwei Variablen (DistributorPrice und ProductColorIsBlack) erstellt. Die Variable DistributorPrice beinhaltet den Wert des Händlerpreises. Dieser Preis wird mithilfe des Faktors 0.75 vom Listenpreis berechnet. Die Variable ProductColorIsBlack beinhaltet den Wert, ob die Produktfarbe Schwarz ist. Innerhalb des Select-Blocks werden die beiden Variablen ausgegeben. Der gesamte Beispiel Code ist wie folgt aufgelistet: Das komplette Visual Studio 2008 Projekt kann unter folgende URL heruntergeladen werden: LinqLetSample0001.zip
let DistributorPrice = (p.ListPrice*Convert.ToDecimal(0.75))
let ProductColorIsBlack = (p.Color != null && p.Color == "Black")
select new
{
ProductCategoryName = pc.Name,
ProductSubCategoryName = psc.Name,
ProductName = p.Name,
p.ListPrice,
DistributorPrice,
ProductColorIsBlack
};
using System.Linq;
namespace LinqLetSample0001
{
internal class Program
{
private static void Main(string[] args)
{
var db = new AdventureWorksDataContext();
var qry = from pc in db.ProductCategories
join psc in db.ProductSubcategories on pc.ProductCategoryID equals psc.ProductCategoryID
join p in db.Products on psc.ProductSubcategoryID equals p.ProductSubcategoryID
let DistributorPrice = (p.ListPrice * Convert.ToDecimal(0.75))
let ProductColorIsBlack = (p.Color != null && p.Color == "Black")
select new
{
ProductCategoryName = pc.Name,
ProductSubCategoryName = psc.Name,
ProductName = p.Name,
p.ListPrice,
DistributorPrice,
ProductColorIsBlack
};
foreach (var item in qry)
{
Console.WriteLine("Product Category : " + item.ProductCategoryName);
Console.WriteLine("Product Sub Category : " + item.ProductCategoryName);
Console.WriteLine("Product : " + item.ProductName);
Console.WriteLine("Product Distributor Price: " + item.DistributorPrice);
Console.WriteLine("Product List Price : " + item.ListPrice);
Console.WriteLine("Product Color is Black : " + item.ProductColorIsBlack);
Console.WriteLine();
}
Console.ReadLine();
}
}
}
2008-05-11
Die let-Klausel (clause) in LINQ
using System;
Subscribe to:
Post Comments (Atom)
.NET Community (2)
.NET Framework 2.0 SP1 (1)
.NET Framework 3.5 (2)
.NET Framework 3.5 Service Pack 1 Beta (1)
.NET Framework 4.0 (1)
.NET Reflector (1)
070-541 (1)
070-630 (11)
Access 2007 (1)
ADO.NET (1)
ADO.NET Entity Framework (6)
Alan Kay (1)
Alan Lakein (1)
Albert Einstein (4)
Alte chinesische Lebensweisheit (1)
Amerikanische Managerweisheit (1)
Android (1)
Antonio Mingote (1)
Archeopsyche (1)
ASP.NET 3.5 Service Pack 1 Beta (1)
Aus Arabien (1)
Aus China (1)
Aus Russland (1)
Axum (2)
Bedürfnis (1)
Beta (1)
Bienvenue Chez Les Ch'tis (1)
Browsers (1)
Buch (4)
Burcu Sönmez (1)
C# (1)
C# 2008 - Profihandbuch und Referenz (1)
Campus (1)
Capacity Planning (3)
Certified Architect for SharePoint (1)
Computer Batteries (1)
CutePDF (1)
Dakota-Indianer (1)
Danny Kaye (1)
Datenbank Allgemein (1)
donationcoder (1)
dotnet-snippets.de (1)
E-mail (1)
Eisenhower-Prinzip (1)
Elbert Hubbard (1)
Entity Klassen (1)
Eric Berne (2)
Erich Fried (1)
Ernst R. Hauschka (1)
Excel (1)
Exchange 2010 (2)
Exteropsyche (1)
Film (4)
Fly Me To The Moon (1)
Form Server 2007 (1)
Free (3)
Free E-Book (7)
Free Icon Set (2)
Free Software (2)
Free WinForm Controls (2)
Fun (1)
Games (1)
gehe langsam (1)
GEVER Office (1)
Gotthold Ephraim Lessing (1)
GroupBy (1)
Groupware (1)
Heinrich Heine (1)
Hello World (1)
Henry David Thoreau (1)
Hippokrates (1)
HP Notebook (1)
InfoPath 2007 (3)
Intersect (1)
iPhone (1)
iPhone 3.0 (1)
IPv6 (1)
IT Certifications (1)
James Russell (1)
Jean-Jacques Rousseau (1)
Johann Wolfgang von Goethe (1)
John Lennon (1)
Klein und Aber (1)
Konfuzius (2)
Krypton Suite (1)
Laotse (1)
Leonardo da Vinci (2)
LINQ (46)
LINQ to DataSet (7)
LINQ to Objects (10)
LINQ to SQL (28)
LINQ to XML (13)
Lord of the Rings (1)
Machine (1)
Mahatma Gandhi (3)
Mao Tse-tung (1)
Mega Mario (1)
Mein Buch LINQ (2)
Message (1)
Metaebene (1)
Microsoft .NET Framework 2.0 (1)
Microsoft .NET Framework 3.5 (1)
Microsoft Axum (2)
Microsoft Certified Master for SharePoint (1)
Microsoft Expression Studio (1)
Microsoft Filter Pack (1)
Microsoft KB (36)
Microsoft Network Monitor (1)
Microsoft Office (1)
Microsoft Office SharePoint Server 2007 (1)
Microsoft Outlook (1)
Microsoft SharePoint 2010 (1)
Microsoft SQL Server 2005 Service Pack 2 (1)
Microsoft Visual Basic for Applications (1)
Microsoft Visual Studio 2005 Express Edition (2)
Microsoft Visual Studio 2005 Professional Edition (2)
Microsoft Visual Studio 2005 Standard Edition (2)
Microsoft Visual Studio 2005 Team Edition for Software Testers (1)
Microsoft Visual Studio 2005 Team Foundation Server (1)
Microsoft Visual Studio Team System 2008 Team Foundation Server (2)
Microsoft Windows (1)
Microsoft Windows XP (1)
MOSS 2007 (1)
MOSS 2007 and Extranet (1)
MOSS 2007 Architecture (1)
MOSS 2007 Best Practices (2)
MOSS 2007 Configuration (1)
MOSS 2007 Customizing (1)
MOSS 2007 Deployment (7)
MOSS 2007 Development (6)
MOSS 2007 Interview Questions (1)
MOSS 2007 Presentations (1)
MOSS 2007 Production (1)
MOSS 2007 Security (2)
Movie (2)
MSDN Code Gallery (1)
MSDN Magazine (2)
msiexec (1)
MSSQLTips (24)
Neopsyche (1)
NET Framework 3.5 Service Pack 1 (1)
Network Tools (1)
Ney (1)
Ney Taksimi (1)
Noël Coward (1)
Object Relational Mapping (1)
Office 2002 Development (1)
Office 2003 Development (1)
Office 2007 (1)
Office 2007 Development (2)
Office 2007 System (1)
Office SharePoint Server 2007 (2)
Office SharePoint Server 2007 Architecture (21)
Office SharePoint Server 2007 Best Practices (8)
Office SharePoint Server 2007 Business Data Catalog (1)
Office SharePoint Server 2007 Configuration (2)
Office SharePoint Server 2007 Deployment (13)
Office SharePoint Server 2007 Development (30)
Office SharePoint Server 2007 Features (2)
Office SharePoint Server 2007 Guidance (1)
Office SharePoint Server 2007 Operating (2)
Office SharePoint Server 2007 Performance (1)
Office SharePoint Server 2007 Presentations (1)
Office SharePoint Server 2007 Security (2)
Office SharePoint Server 2007 Service Pack (3)
Office Suites (1)
Office Visio 2007 Professional (1)
Online Communications (1)
Operating Systems (1)
Oracle Forms (1)
Oscar Wilde (1)
Outlook 2002 Development (1)
Outlook 2003 Development (1)
OXBA (1)
Parallel Computing Platform (1)
Parallel Programming (1)
PDF Creator (1)
Peter F. Drucker (2)
Peter Frankenfeld (1)
Philosophie (Sonstiges) (1)
Photosynth (1)
PowerShell (1)
Product Id (1)
Product Key (1)
Project Server 2007 (1)
Psychologie (2)
Pythagoras (1)
Query Operators (2)
Quickstart (1)
Reach (1)
Recall (1)
Relational Database Design (1)
ReSharper (2)
Rollo May (1)
Screenshot Captor (1)
Script (1)
Script Method (1)
Search Center (2)
Search Server 2008 (1)
Search Server 2008 and Search Server 2008 Express (1)
Sender (1)
Service Pack (1)
SET ANSI_NULLS (1)
Shakespeare (1)
Shared Services Provider (1)
SharePoint Capacity Planning Tool (1)
SharePoint Designer 2007 (2)
SharePoint Server 2010 (1)
Shunryu Suzuki (1)
Sigmund Freud (3)
SilverLight (2)
Silverlight 2 (1)
Software (2)
Sokrates (1)
Sophokles (1)
SP1 (1)
Spiele der Erwachsenen (1)
SQL (3)
SQL Commands (1)
SQL Server 2000 (1)
SQL Server 2005 (4)
SQL Server 2005 Administration (2)
SQL Server 2005 Development (4)
SQL Server 2005 Disaster Recovery (1)
SQL Server 2005 Performance (1)
SQL Server 2005 Reporting Services (1)
SQL Server 2008 (3)
SQL Server 2008 Auditing (1)
SQL Server 2008 Beispiel Datenbanken (2)
SQL Server 2008 Development (8)
SQL Server 2008 Sample Databases (2)
SQL Server 2008 Samples (1)
SQL Server 2008 Service Pack 1 (1)
SQL Server 2008 Trial (1)
SQL Server Compact 3.5 (2)
SQL Server Express Edition (1)
SQL Server Performance Tips (1)
SQLMetal (1)
Standard Query Operators (1)
Strategie (1)
String.Format (1)
Stupidedia (1)
Super Mario Bros (1)
Sysinternals (1)
System Center Capacity Planner 2007 (1)
T-SQL (1)
T-SQL Samples (3)
Take (1)
The Hunt For Gollum (1)
TIFF (1)
Tools (2)
Training Demo (1)
Training Kit (1)
Transaktionsanalyse (1)
Umfrage (1)
VBA (1)
Virtual Earth 3D (1)
Virtual Lab (2)
Virtual PC (1)
Virtual TechDays (1)
Visual Basic (1)
Visual Basic 2008 (1)
Visual Studio 2005 (3)
Visual Studio 2005 Fix (2)
Visual Studio 2005 Service Pack 1 (1)
VIsual Studio 2008 (3)
Visual Studio 2008 Beta 2 (3)
Visual Studio 2008 Express Edition (1)
Visual Studio 2008 Fix (2)
Visual Studio 2008 RTM (3)
Visual Studio 2008 Service Pack 1 (1)
Visual Studio 2008 Service Pack 1 Beta (2)
Visual Studio 2010 (1)
Visual Studio 2010 Team Suite (1)
Visual Studio 2010 Team System (1)
Visual Studio Add-In (1)
Visual Studio Orcas (1)
Visual Studio Orcas Beta 1 (2)
Visual Studio Team System 2008 Team Foundation Server (1)
VS 2008 (3)
WBS Modeler (1)
Webcast (1)
Wenn du es eilig hast (1)
White Paper (1)
Wikipedia (4)
Windows 7 (4)
Windows Server 2008 (3)
Windows Server 2008 Service Pack (1)
Windows SharePoint Services 3.0 Deployment (2)
Windows SharePoint Services 3.0 Development (6)
Windows SharePoint Services 3.0 Security (1)
Windows SharePoint Services 3.0 Service Pack (1)
Windows Sysinternals (4)
Windows Vista (1)
Windows Vista Service Pack (1)
Windows XP Service Pack (1)
WPF (1)
Writing Secure Code (1)
WSPBuilder (1)
WSRP Toolkit for SharePoint (1)
WSS 3.0 Development (1)
Wunsch (1)
Youtube (1)
Zeitmanagement (1)
Zitat (28)
Ödipuskonflikt (1)
.NET Framework 2.0 SP1 (1)
.NET Framework 3.5 (2)
.NET Framework 3.5 Service Pack 1 Beta (1)
.NET Framework 4.0 (1)
.NET Reflector (1)
070-541 (1)
070-630 (11)
Access 2007 (1)
ADO.NET (1)
ADO.NET Entity Framework (6)
Alan Kay (1)
Alan Lakein (1)
Albert Einstein (4)
Alte chinesische Lebensweisheit (1)
Amerikanische Managerweisheit (1)
Android (1)
Antonio Mingote (1)
Archeopsyche (1)
ASP.NET 3.5 Service Pack 1 Beta (1)
Aus Arabien (1)
Aus China (1)
Aus Russland (1)
Axum (2)
Bedürfnis (1)
Beta (1)
Bienvenue Chez Les Ch'tis (1)
Browsers (1)
Buch (4)
Burcu Sönmez (1)
C# (1)
C# 2008 - Profihandbuch und Referenz (1)
Campus (1)
Capacity Planning (3)
Certified Architect for SharePoint (1)
Computer Batteries (1)
CutePDF (1)
Dakota-Indianer (1)
Danny Kaye (1)
Datenbank Allgemein (1)
donationcoder (1)
dotnet-snippets.de (1)
E-mail (1)
Eisenhower-Prinzip (1)
Elbert Hubbard (1)
Entity Klassen (1)
Eric Berne (2)
Erich Fried (1)
Ernst R. Hauschka (1)
Excel (1)
Exchange 2010 (2)
Exteropsyche (1)
Film (4)
Fly Me To The Moon (1)
Form Server 2007 (1)
Free (3)
Free E-Book (7)
Free Icon Set (2)
Free Software (2)
Free WinForm Controls (2)
Fun (1)
Games (1)
gehe langsam (1)
GEVER Office (1)
Gotthold Ephraim Lessing (1)
GroupBy (1)
Groupware (1)
Heinrich Heine (1)
Hello World (1)
Henry David Thoreau (1)
Hippokrates (1)
HP Notebook (1)
InfoPath 2007 (3)
Intersect (1)
iPhone (1)
iPhone 3.0 (1)
IPv6 (1)
IT Certifications (1)
James Russell (1)
Jean-Jacques Rousseau (1)
Johann Wolfgang von Goethe (1)
John Lennon (1)
Klein und Aber (1)
Konfuzius (2)
Krypton Suite (1)
Laotse (1)
Leonardo da Vinci (2)
LINQ (46)
LINQ to DataSet (7)
LINQ to Objects (10)
LINQ to SQL (28)
LINQ to XML (13)
Lord of the Rings (1)
Machine (1)
Mahatma Gandhi (3)
Mao Tse-tung (1)
Mega Mario (1)
Mein Buch LINQ (2)
Message (1)
Metaebene (1)
Microsoft .NET Framework 2.0 (1)
Microsoft .NET Framework 3.5 (1)
Microsoft Axum (2)
Microsoft Certified Master for SharePoint (1)
Microsoft Expression Studio (1)
Microsoft Filter Pack (1)
Microsoft KB (36)
Microsoft Network Monitor (1)
Microsoft Office (1)
Microsoft Office SharePoint Server 2007 (1)
Microsoft Outlook (1)
Microsoft SharePoint 2010 (1)
Microsoft SQL Server 2005 Service Pack 2 (1)
Microsoft Visual Basic for Applications (1)
Microsoft Visual Studio 2005 Express Edition (2)
Microsoft Visual Studio 2005 Professional Edition (2)
Microsoft Visual Studio 2005 Standard Edition (2)
Microsoft Visual Studio 2005 Team Edition for Software Testers (1)
Microsoft Visual Studio 2005 Team Foundation Server (1)
Microsoft Visual Studio Team System 2008 Team Foundation Server (2)
Microsoft Windows (1)
Microsoft Windows XP (1)
MOSS 2007 (1)
MOSS 2007 and Extranet (1)
MOSS 2007 Architecture (1)
MOSS 2007 Best Practices (2)
MOSS 2007 Configuration (1)
MOSS 2007 Customizing (1)
MOSS 2007 Deployment (7)
MOSS 2007 Development (6)
MOSS 2007 Interview Questions (1)
MOSS 2007 Presentations (1)
MOSS 2007 Production (1)
MOSS 2007 Security (2)
Movie (2)
MSDN Code Gallery (1)
MSDN Magazine (2)
msiexec (1)
MSSQLTips (24)
Neopsyche (1)
NET Framework 3.5 Service Pack 1 (1)
Network Tools (1)
Ney (1)
Ney Taksimi (1)
Noël Coward (1)
Object Relational Mapping (1)
Office 2002 Development (1)
Office 2003 Development (1)
Office 2007 (1)
Office 2007 Development (2)
Office 2007 System (1)
Office SharePoint Server 2007 (2)
Office SharePoint Server 2007 Architecture (21)
Office SharePoint Server 2007 Best Practices (8)
Office SharePoint Server 2007 Business Data Catalog (1)
Office SharePoint Server 2007 Configuration (2)
Office SharePoint Server 2007 Deployment (13)
Office SharePoint Server 2007 Development (30)
Office SharePoint Server 2007 Features (2)
Office SharePoint Server 2007 Guidance (1)
Office SharePoint Server 2007 Operating (2)
Office SharePoint Server 2007 Performance (1)
Office SharePoint Server 2007 Presentations (1)
Office SharePoint Server 2007 Security (2)
Office SharePoint Server 2007 Service Pack (3)
Office Suites (1)
Office Visio 2007 Professional (1)
Online Communications (1)
Operating Systems (1)
Oracle Forms (1)
Oscar Wilde (1)
Outlook 2002 Development (1)
Outlook 2003 Development (1)
OXBA (1)
Parallel Computing Platform (1)
Parallel Programming (1)
PDF Creator (1)
Peter F. Drucker (2)
Peter Frankenfeld (1)
Philosophie (Sonstiges) (1)
Photosynth (1)
PowerShell (1)
Product Id (1)
Product Key (1)
Project Server 2007 (1)
Psychologie (2)
Pythagoras (1)
Query Operators (2)
Quickstart (1)
Reach (1)
Recall (1)
Relational Database Design (1)
ReSharper (2)
Rollo May (1)
Screenshot Captor (1)
Script (1)
Script Method (1)
Search Center (2)
Search Server 2008 (1)
Search Server 2008 and Search Server 2008 Express (1)
Sender (1)
Service Pack (1)
SET ANSI_NULLS (1)
Shakespeare (1)
Shared Services Provider (1)
SharePoint Capacity Planning Tool (1)
SharePoint Designer 2007 (2)
SharePoint Server 2010 (1)
Shunryu Suzuki (1)
Sigmund Freud (3)
SilverLight (2)
Silverlight 2 (1)
Software (2)
Sokrates (1)
Sophokles (1)
SP1 (1)
Spiele der Erwachsenen (1)
SQL (3)
SQL Commands (1)
SQL Server 2000 (1)
SQL Server 2005 (4)
SQL Server 2005 Administration (2)
SQL Server 2005 Development (4)
SQL Server 2005 Disaster Recovery (1)
SQL Server 2005 Performance (1)
SQL Server 2005 Reporting Services (1)
SQL Server 2008 (3)
SQL Server 2008 Auditing (1)
SQL Server 2008 Beispiel Datenbanken (2)
SQL Server 2008 Development (8)
SQL Server 2008 Sample Databases (2)
SQL Server 2008 Samples (1)
SQL Server 2008 Service Pack 1 (1)
SQL Server 2008 Trial (1)
SQL Server Compact 3.5 (2)
SQL Server Express Edition (1)
SQL Server Performance Tips (1)
SQLMetal (1)
Standard Query Operators (1)
Strategie (1)
String.Format (1)
Stupidedia (1)
Super Mario Bros (1)
Sysinternals (1)
System Center Capacity Planner 2007 (1)
T-SQL (1)
T-SQL Samples (3)
Take (1)
The Hunt For Gollum (1)
TIFF (1)
Tools (2)
Training Demo (1)
Training Kit (1)
Transaktionsanalyse (1)
Umfrage (1)
VBA (1)
Virtual Earth 3D (1)
Virtual Lab (2)
Virtual PC (1)
Virtual TechDays (1)
Visual Basic (1)
Visual Basic 2008 (1)
Visual Studio 2005 (3)
Visual Studio 2005 Fix (2)
Visual Studio 2005 Service Pack 1 (1)
VIsual Studio 2008 (3)
Visual Studio 2008 Beta 2 (3)
Visual Studio 2008 Express Edition (1)
Visual Studio 2008 Fix (2)
Visual Studio 2008 RTM (3)
Visual Studio 2008 Service Pack 1 (1)
Visual Studio 2008 Service Pack 1 Beta (2)
Visual Studio 2010 (1)
Visual Studio 2010 Team Suite (1)
Visual Studio 2010 Team System (1)
Visual Studio Add-In (1)
Visual Studio Orcas (1)
Visual Studio Orcas Beta 1 (2)
Visual Studio Team System 2008 Team Foundation Server (1)
VS 2008 (3)
WBS Modeler (1)
Webcast (1)
Wenn du es eilig hast (1)
White Paper (1)
Wikipedia (4)
Windows 7 (4)
Windows Server 2008 (3)
Windows Server 2008 Service Pack (1)
Windows SharePoint Services 3.0 Deployment (2)
Windows SharePoint Services 3.0 Development (6)
Windows SharePoint Services 3.0 Security (1)
Windows SharePoint Services 3.0 Service Pack (1)
Windows Sysinternals (4)
Windows Vista (1)
Windows Vista Service Pack (1)
Windows XP Service Pack (1)
WPF (1)
Writing Secure Code (1)
WSPBuilder (1)
WSRP Toolkit for SharePoint (1)
WSS 3.0 Development (1)
Wunsch (1)
Youtube (1)
Zeitmanagement (1)
Zitat (28)
Ödipuskonflikt (1)
0 Kommentare:
Post a Comment