不确定这是否会有所帮助,但是我在LinqPad中写入的一次性查询有类似的问题,并最终定义并使用了像这样的临时表。
[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
);
}
用法是一样的东西
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();
}
在我的情况下,临时表只有一个INT列,但你应该能够定义任何列(S)输入您希望,(只要你有一个主键)。
你不能返回结果集而不是2100参数吗? – 2011-05-25 09:25:25
您是否考虑批量插入操作? – 2011-05-25 09:25:57
在[此连接问题]中有一个解决方案使用单个XML参数(https://connect.microsoft.com/VisualStudio/feedback/details/475984/use-an-xml-type-parameter-in-order-to-超过最2100-参数限制功能于LINQ到SQL的当滤波-经由-A-本地集合)。但我同意Guillame--如果可以的话,你应该在两个数据库之间进行协调。 – Rup 2011-05-25 09:37:37