我无法尝试这个,但尝试使用类似 where 子句的东西。
from e in ctx.CompositeEntities
where ids.Where(i => e.KeyA == i.Item1 && e.KeyB == i.Item2).Count() > 0
select e;
===== 编辑 =====
好吧,它失败了,但同样的例外,谢谢你的鼓励。
假设您的键是 int 而不是 bigint,那么以下内容呢
public class e1 {
public int KeyA { get; set; }
public int KeyB { get; set; }
}
public class e1Configuration : EntityTypeConfiguration<e1> {
public e1Configuration()
: base() {
HasKey(x => new { x.KeyA, x.KeyB });
}
}
public class TestEFContext : DbContext {
public IDbSet<e1> es { get; set; }
public TestEFContext(String cs)
: base(cs) {
Database.SetInitializer<TestEFContext>(new DropCreateDatabaseAlways<TestEFContext>());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new e1Configuration());
}
}
class Program {
static void Main(String[] args) {
using (TestEFContext c = new TestEFContext(@"Data Source=ALIASTVALK;Initial Catalog=TestEF;Integrated Security=True; MultipleActiveResultSets=True")) {
c.es.Add(new e1 { KeyA = 1, KeyB = 1 });
c.es.Add(new e1 { KeyA = 1, KeyB = 2 });
c.es.Add(new e1 { KeyA = Int32.MaxValue, KeyB = 2 });
c.SaveChanges();
}
List<Tuple<int, int>> ids = new List<Tuple<int, int>> {
new Tuple<int, int>(1, 1),
new Tuple<int, int>(Int32.MaxValue, 2),};
List<Int64> lis = (from t in ids select (Int64)t.Item1 * 2^ 32 + t.Item2).ToList();
using (TestEFContext c0 = new TestEFContext(@"Data Source=ALIASTVALK;Initial Catalog=TestEF;Integrated Security=True; MultipleActiveResultSets=True")) {
var v = from e in c0.es
where lis.Contains((Int64)e.KeyA * 2 ^ 32 + e.KeyB)
select e;
Console.WriteLine(v.Count());
}
}
}