2. 限制操作符—【LINQ标准查询操作符】

public class Where_LINQ
    {
        public static  string ContextString = System.Configuration.ConfigurationSettings.AppSettings["ContextString"].ToString();
        public static void Print()        
        { 
            DataContext context = new DataContext(ContextString);
            Table<Contact> contact = context.GetTable<Contact>();

            var whereQuery = from c in contact
                                             where c.FirstName.StartsWith("S")
                                             select new { c.FirstName, c.LastName, c.EmailAddress };
            foreach (var item in whereQuery.Take(10))
            {
                Console.WriteLine(item.FirstName + " " + item.LastName + " " + item.EmailAddress);
            }

            Console.WriteLine("\n");
            Console.WriteLine("===== Method Syntex =====");
            var whereMethodSyntex = contact.Select(con => new { con.FirstName, con.LastName, con.EmailAddress }).Where(c => c.FirstName.StartsWith("S"));
            foreach (var i in whereMethodSyntex.Take(10))
            {
                Console.WriteLine(i.FirstName + " " + i.LastName + " " + i.EmailAddress);
            }                

            Console.ReadKey();
        }
    }
posted @ 2010-04-17 21:17  CityWalker  阅读(184)  评论(0编辑  收藏  举报
天天来