Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 4 编译查询只允许使用标量参数!_Entity Framework 4 - Fatal编程技术网

Entity framework 4 编译查询只允许使用标量参数!

Entity framework 4 编译查询只允许使用标量参数!,entity-framework-4,Entity Framework 4,我在EF4中使用POCO对象,没有生成任何T4模板 我有一个DataContext类,它封装了所有对象集,类似这样 public sealed class DataContext :IDisposable { public IObjectSet GetObjectSet() where T : MyBase { object objectSet = null; this.objectSets.TryGetValue(typeof(T), out objectSet);

我在EF4中使用POCO对象,没有生成任何T4模板

我有一个DataContext类,它封装了所有对象集,类似这样


 public sealed class DataContext :IDisposable
 {

 public IObjectSet GetObjectSet() where T : MyBase
 {

   object objectSet = null;

   this.objectSets.TryGetValue(typeof(T), out objectSet);

   if (objectSet == null)
   {
    objectSet = this.context.CreateObjectSet();
    this.objectSets.Add(typeof(T), objectSet);
   }
   return (IObjectSet)objectSet;
  }

  public ObjectContext ObjectContext
  {            
     get
       { 
       return this.context; 
      }  
  }
}
当我编写下面的编译查询并尝试将该类作为参数之一传入时,它会给出一个运行时错误,表示只允许使用标量参数

static readonly Func<ObjectContext , DataContext, string, int?> getOperationByOrchestrationName

  = CompiledQuery.Compile(

  (ObjectContext ctx, DataContext container, string name) =>

   (from or in container.GetObjectSet<MyOrClass>()

   join op in container.GetObjectSet<MyOpClass>()

   on or.Id equals op.Id

   where op.Name == name
   select op.Id).FirstOrDefault()

  );

对于任何感兴趣的人来说,如果您从编译后的查询返回IQueryable并调用任何可以更改查询的方法(singleordefault或firstordefault等),您将无法从编译后的查询中获益

    static readonly Func, IObjectSet, string, IQueryable> 
   getOperationByOrchestrationName   
    = CompiledQuery.Compile(
      (ObjectContext ctx, IObjectSet ors, IObjectSet ops,string operationName) =>
       from or in ors
       join op in ops
       on or.Id equals op.Id
       where op.Name == name
       select op.Id
     );