IT tutorials
 
Technology
 

LINQ to SharePoint and SPMetal : Querying Data Using LINQ to SharePoint (part 3) - Result Shaping Using LINQ

12/2/2013 3:24:43 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Result Shaping Using LINQ

One of the benefits of LINQ is its ability to shape result sets while still retaining a type-safe output. We can explore this functionality by adding another button to our sample application; this time, label it Basic Result Shaping and add the following code:

private void button7_Click(object sender, EventArgs e)
{
using(HireSampleDataContext dxRead = new HireSampleDataContext(SiteUrl.Text))
{

//create a stringbuilder to store the CAML query
StringBuilder sb = new StringBuilder();

using (StringWriter logWriter = new StringWriter(sb))
{
//log the generated CAML query to a StringWriter
dxRead.Log = logWriter;

dxRead.ObjectTrackingEnabled = false;

var basicQuery = from c in dxRead.HireContracts
where c.ContractStartDate.Value < DateTime.Now
orderby c.ContractStartDate
select new{
c.ContractId,
c.ContractStartDate,
c.ContractEndDate,
Creator = c.DocumentCreatedBy.Substring(
c.DocumentCreatedBy.LastIndexOf(‘\\’)+1),
Version = "v" + c.Version.Value.ToString("0.000")
};


dataGridView1.DataSource = basicQuery.ToList();
}

string fileName = Path.Combine(Path.GetTempPath(), "tmpCaml.xml");

XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
doc.Save(fileName);

//point the browser control to the temporary generated CAML file
webBrowser1.Navigate(fileName);
}
}



Notice the creation of a new anonymous type as part of the LINQ query. The new type consists of fields from the returned entity together with some string manipulation functions to get the results into the appropriate format.

Notice when examining the generated CAML for this query that the string manipulations have not been translated. Although CAML does not support these operations, the LINQ to SharePoint provider still allows them as part of the query because they are performed on the results and are therefore unlikely to cause significant performance issues.

 
Others
 
- LINQ to SharePoint and SPMetal : Querying Data Using LINQ to SharePoint (part 2) - Performing a Simple Query
- LINQ to SharePoint and SPMetal : Querying Data Using LINQ to SharePoint (part 1) - Query Limitations
- System Center Configuration Manager 2007 : Client Deployment (part 4) - Client Installation in Image Deployment
- System Center Configuration Manager 2007 : Client Deployment (part 3) - Client Push Installation Wizard
- System Center Configuration Manager 2007 : Client Deployment (part 2) - Manual Installation, Client Push Installation
- System Center Configuration Manager 2007 : Client Deployment (part 1) - Command-Line Properties
- Troubleshooting Exchange Server 2010 : Troubleshooting Client Connectivity (part 2)
- Troubleshooting Exchange Server 2010 : Troubleshooting Client Connectivity (part 1) - Troubleshooting Autodiscover
- Troubleshooting Exchange Server 2010 : Troubleshooting Mail Flow (part 3) - Exchange Mail Flow Troubleshooter
- Troubleshooting Exchange Server 2010 : Troubleshooting Mail Flow (part 2) - Message Tracking
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us