LINQ
Swathi discussed LINQ and the many advantages it brings. She provided three examples:
var feeType = from p in db.FEETYPEs
where p.FEEDESC.Contains("Permit")
select p;
XDocument xmlSource = XDocument.Load("XMLFile1.xml");
var books = from book in xmlSource.Descendants("Table1")
select new
{
Name = book.Element("bookName").Value,
Author = book.Element("author").Value
};
//using Query Expression
string[] names = { "Tom", "Rick", "Harry", "Mary", "Jay" };
IEnumerable query = from n in names
where n.Contains("a") // Filter elements
orderby n.Length // Sort elements
select n; // Translate each element (project)
//using Lambda Expression
IEnumerable lambdaQuery = names.Where(n => n.Contains("a")).OrderBy(n => n.Length);
Finally, Swathi showed how we can now use LINQ in H8:
var requests = NewComponent();
requests.Load(x => (x.RequestType.RequestType == "Graffiti" && x.IsAssigned == true) || x.RequestType.RequestType == "Dead Animal")
No comments:
Post a Comment