Not sure if this will help, but I had a similar problem for the one-time query I wrote in LinqPad, and ultimately determined and used a temporary table like this.
[Table(Name="#TmpTable1")] public class TmpRecord { [Column(DbType="Int", IsPrimaryKey=true, UpdateCheck=UpdateCheck.Never)] public int? Value { get; set; } } public Table<TmpRecord> TmpRecords { get { return base.GetTable<TmpRecord>(); } } public void DropTable<T>() { ExecuteCommand( "DROP TABLE " + Mapping.GetTable(typeof(T)).TableName ); } public void CreateTable<T>() { ExecuteCommand( typeof(DataContext) .Assembly .GetType("System.Data.Linq.SqlClient.SqlBuilder") .InvokeMember("GetCreateTableCommand", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod , null, null, new[] { Mapping.GetTable(typeof(T)) } ) as string ); }
Usage is something like
void Main() { List<int> ids = .... this.Connection.Open(); // Note, if the connection is not opened here, the temporary table // will be created but then dropped immediately. CreateTable<TmpRecord>(); foreach(var id in ids) TmpRecords.InsertOnSubmit( new TmpRecord() { Value = id}) ; SubmitChanges(); var list1 = (from r in CustomerTransaction join tt in TmpRecords on r.CustomerID equals tt.Value where .... select r).ToList(); DropTable<TmpRecord>(); this.Connection.Close();
}
In my case, the temporary table had only one int column, but you should be able to define whatever type of columns you want (as long as you have the primary key).
sgmoore
source share