在内部联接中选择左表到实体框架拦截器中的DbScanExpression

时间:2015-04-16 15:40:31

标签: c# entity-framework entity-framework-6

除了回答here的SO问题之外,我还试图选择右表中的所有列,而不必与左表中的UserId一起明确指定列名。

关于如何做到这一点的任何想法?



public override DbExpression Visit(DbScanExpression expression)
{
    var table = expression.Target.ElementType as EntityType;
    if (table != null && table.Name == "User")
    {
        return expression.InnerJoin(
            DbExpressionBuilder.Scan(expression.Target.EntityContainer.BaseEntitySets.Single(s => s.Name == "TennantUser")),
            (l, r) =>
                DbExpressionBuilder.Equal(
                    DbExpressionBuilder.Property(l, "UserId"),
                    DbExpressionBuilder.Property(r, "UserId")
                )
        )
        .Select(exp => 
            new { 
                UserId = exp.Property("l").Property("UserId"), 
                Email = exp.Property("l").Property("Email") 
            });
    }

    return base.Visit(expression);
}




2 个答案:

答案 0 :(得分:0)

也许答案有点晚,但无论如何它可能有助于某人节省时间

self.MakeCall = function(theList, chunkSize){
   //Split list into what will be processed and what should be held
    var processList = theList.slice(0,chunkSize);
    var holdList = theList.slice(chunkSize);

    return $q.all(processList).then(function(result) {
      //If holdList is empty you are finished
      if(holdList <= 0) {
        return result;
      }
      else {
        //More items make recursive call to process next set
        return self.MakeCall(holdList, chunkSize);
      }
    });
  };
//Initialize Recursive call
self.MakeCall(self.contacts);

答案 1 :(得分:0)

Expression.New(typeof(StringComparer<>).MakeGenericType(typeOfItemInList))