background preloader

Linq

Facebook Twitter

Requête Linq to XML. Interrogation modele conceptuel. Procédure pas à pas : écriture de requêtes en C# (LINQ) Pour créer un projet Pour ajouter la source de données Pour ajouter un nouvel étudiant à la liste des étudiants Pour créer une requête simple // Create the query.// The first line could also be written as "var studentQuery =" IEnumerable<Student> studentQuery = from student in students where student.Scores[0] > 90 select student; Pour exécuter la requête // Execute the query.// var could be used here also.foreach (Student student in studentQuery) { Console.WriteLine("{0}, {1}", student.Last, student.First); } // Omelchenko, Svetlana// Garcia, Cesar// Fakhouri, Fadi// Feng, Hanying// Garcia, Hugo// Adams, Terry// Zabokritski, Eugene// Tucker, Michael Pour ajouter une autre condition de filtre where student.Scores[0] > 90 && student.Scores[3] < 80 Pour classer les résultats.

Procédure pas à pas : écriture de requêtes en C# (LINQ)

LINQ to XML. Download source code - 7.59 KB Introduction Working with XML using Microsoft's .NET Framework version 2.0 and below is a cumbersome task.

LINQ to XML

The API available follows the W3C DOM model, and is document-centric. Everything begins with the document; you can't create elements without having a document; even a fragment of XML is a document. In the latest release of the .NET Framework, however, this has changed. LINQ (How Do I in C#) How to: Query the Contents of Files in a Folder (LINQ)

This example shows how to query over all the files in a specified directory tree, open each file, and inspect its contents.

How to: Query the Contents of Files in a Folder (LINQ)

This type of technique could be used to create indexes or reverse indexes of the contents of a directory tree. A simple string search is performed in this example. However, more complex types of pattern matching can be performed with a regular expression. For more information, see How to: Combine LINQ Queries with Regular Expressions. Create a Visual Studio project that targets the .NET Framework version 3.5. For intensive query operations over the contents of multiple types of documents and files, consider using the Windows Desktop Search engine. LINQ To XML - C# Tutorials.

LINQ-ing to XML - XML tutorial. This article was originally published in VSJ, which is now part of Developer Fusion. LINQ isn’t just about SQL and it isn’t even just about database. After looking last month in some detail at the basic idea behind LINQ, it is instructive to examine probably its second most common application – working with XML. There always was good XML support in .NET but LINQ adds a set of classes that makes it easier to work with XML, particularly if you’re not an XML specialist.

There are a number of standard protocols and ways of working with XML – Xpath, SAX, DOM and so on. All of them are good but they all focus on some specific particular aspect of XML and a particular way of getting the job done. Even if you aren’t interested in working with XML, looking at how LINQ handles a more complicated data structure, a tree in this case, is instructive and has a lot to teach you about the way LINQ is designed, how it works and how you might extend it to other data structures. Xelement root.Add(child1); Linq to XML Tutorial. Download source This is an introduction to Linq to XML showing how to read, insert, update and delete from an XML file.

First of all lets look at the XML file I will be using: As you can see it’s a very simple list of customers. In my project I have also created a Customer class to represent each customer: Firsly I want to be able to select a single customer based on their ID. Firstly the XML document is loaded using the XDocument class. I’ve created a simple web form that uses an ObjectDataSource with this method to display a customer based on the ID in the query string: The page creates the following table: To get a list of all customers is very similar to getting a single customer, although the method will return a generic list of Customer objects: Here I am also using the orderby operator to order the results by the value of the Surname element.

I have a single method called Save which is used for both inserting and updating. If the value is greater than zero then it is an update. LINQ à 360 degré, Partie 2 , Page 4. Joe Stevens' Blog. I was interested to see how I could use Linq to SQL with WCF Services to load and save data using a Silverlight project. In this post I will expand upon the database I created in my Linq to SQL Tutorial and the console application I wrote for my Set inheritance modifiers with SQLMetal post. The first step is to enable serialisation on my Linq entities so that they can be sent over the wire. To do this in the O/R Designer you can select the white space of the designer and view the DataContext properties. Set the property called Serialization Mode to Unidirectional: If using SQLMetal you can use the serialization command line argument: Enabling unidirectional serialization in either of these two ways adds the necessary DataContract and DataMember attributes to the generated entities and properties: The entities are now in a state where they can be serialised and sent down the wire.

These entities can then be easily used by the client, in this case the Silverlight application: LINQ in C#