Query1: var queryByCity = from cust in customers group cust by cust.City; Query2: ListUsing IEnumerablecities = new List (); cities.Add("New Delhi"); cities.Add("Bangalore"); cities.Add("Hyderabad"); cities.Add("Bombay"); IEnumerable query = from c in cities where c.Length > 8 orderby c select c;
string connectionString = "Data Source=LocalHost; Initial CataLog=SalesOrderManagement;Integrated Security=True"; DataContext db = new DataContext(connectionString); TableYou will see from the above query that the type of result cannot be determined. The query returns an anonymous type with two members - Customer Name and address. A class definition is not written in the program. we use the var keyword in such a situation. When the compiler sees the var keyword, it does not expect what type is the result and prepares to check it by itself.Customers = db.GetTable (); var query = from c in Customers select new { c.Name, c.Address }; foreach (var row in query) { Console.WriteLine(row.Name + row.Address); }
Copyright © 2012 - All Rights Reserved - VKInfotek.com