using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Linq; using System.Data.SqlClient; namespace ConsoleApplication39 { class Program { static void Main(string[] args) { Test(1); Console.WriteLine("------"); Test(0); Console.ReadLine(); } static void Test(int index) { IQueryable<IGenericBaseClass> query = null; DataClasses1DataContext context = new DataClasses1DataContext(); context.Log = Console.Out; //for log only,you can remove it. if(index == 1) query = context.Customers.Cast<IGenericBaseClass>(); else query = context.Orders.Cast<IGenericBaseClass>(); var result = from s1 in query where s1.CustomerID.Contains("V") select s1; foreach (var item in result) { Console.WriteLine(item.CustomerID); } } } public interface IGenericBaseClass { string CustomerID { get; set; } } partial class Customers : IGenericBaseClass { } partial class Orders : IGenericBaseClass { } } |