Posts

Showing posts with the label LINQ

LINQ to XML : XElement and XAttribute

var _CountryLists = (from c in SW_Countries select new { c.ID, c.Name, c.Abbreviation }); var xml = new XElement("root",from c in _CountryLists select new XElement("nodes", new XAttribute("id", c.ID), new XAttribute("abb", c.Abbreviation), new XAttribute("name", c.Name))); return xml.ToString(); xml will return result like this... <root> <nodes id="13" abb="AUS" name="Australia" /> <nodes id="28" abb="MMR" name="Burma" /> <nodes id="33" abb="BRA" name="Brazil" /> <nodes id="35" abb="BTN" name="Bhutan" /> <nodes id="40" abb="CAN" name="Canada" /> <nodes id="43" abb="LKA" name="Sri Lanka" /> <nodes id="46" abb="CHN" name="China...

LINQ - C# Programming

Get DataSource In C# as in most programming languages a variable must be declared before it can be used. In a LINQ query, the from clause comes first in order to introduce the data source (customers) and the range variable (cust). //QEmp is an IEnumerable var QEmp = from e in Emp select e; Filter Probably the most common query operation is to apply a filter in the form of a Boolean expression. The filter causes the query to return only those elements for which the expression is true. The result is produced by using the where clause. The filter in effect specifies which elements to exclude from the source sequence. var QEmp = from e in Emp where e.Country == "India" select e ----AND Condition---- where e.Country == "India" && e.Name == "Ashvin" ----OR Condition---- where e.Country == "India" || e.Name == "Ashvin" Ordering The orderby clause will cause the elements in the...