// Example of scenario such as storing a query in a database and retreiving it // later into the same object model. public static void DLinqQuerySerializationSamples() { Console.WriteLine("DLINQ BASIC SAMPLE - Single Object Model used on both sides of serialization:"); // Write the query against RemoteTable<Customer>, a dummy implementation // of IQueryable RemoteTable <Customer> customers = new RemoteTable <Customer>(); var query = from c in customers where c.City == "London" select new { c.CompanyName, c }; XElement queryXml = query.SerializeQuery(); // On the other side - create a new DataContext, and deserialize // the query xml into a query against this datacontext NorthwindDataContext dbOther = new NorthwindDataContext(); IQueryable queryAfter = dbOther.DeserializeQuery(queryXml); // Print out the IQueryable: "(x, y) => x + y" Console.WriteLine("Deserialized IQueryable:"); Console.WriteLine(" " + queryAfter.ToString()); Console.WriteLine("\n Results: "); queryAfter.Cast <object>().ToList().ForEach(n => Console.WriteLine(" " + n.ToString())); Console.WriteLine(); }
// Example of scenario such as storing a query in a database and retreiving it // later into the same object model. public static void DLinqQuerySerializationSamples() { Console.WriteLine("DLINQ BASIC SAMPLE - Single Object Model used on both sides of serialization:"); // Write the query against RemoteTable<Customer>, a dummy implementation // of IQueryable RemoteTable<Customer> customers = new RemoteTable<Customer>(); var query = from c in customers where c.City == "London" select new {c.CompanyName,c}; XElement queryXml = query.SerializeQuery(); // On the other side - create a new DataContext, and deserialize // the query xml into a query against this datacontext NorthwindDataContext dbOther = new NorthwindDataContext(); IQueryable queryAfter = dbOther.DeserializeQuery(queryXml); // Print out the IQueryable: "(x, y) => x + y" Console.WriteLine("Deserialized IQueryable:"); Console.WriteLine(" " + queryAfter.ToString()); Console.WriteLine("\n Results: "); queryAfter.Cast<object>().ToList().ForEach(n => Console.WriteLine(" " + n.ToString())); Console.WriteLine(); }