实体框架中的"它"是什么

Jon*_*ono 4 c# linq entity-framework

请原谅我,如果以前曾经问过,但我的任何搜索中都没有出现"它".我有两个数据库表Person和Employee建模一个Table-per-Type(例如Employee is-a Person).在我的edmx设计器中,我定义了一个单独的实体Employee,它将每个列映射到它们各自的基础表(例如Name - > Person,Salary - > Employee).

"它"允许我在LINQ表达式中执行这样的操作:

context.Employees.Where("it.Name LIKE 'M%' AND it.Salary > 1234")
Run Code Online (Sandbox Code Playgroud)

是否有任何良好的链接解释我如何期望"它"的行为?我认为它不是一个通用的LINQ,它对Entity Framework有点具体.

编辑0:生成的ObjectContext的C#代码如下:

public partial class TestObjectContext : ObjectContext
{
  // lots of boilerplate removed for clarity

  public ObjectSet<Employee> Employees
  {
    get
    {
      if ((_Employees == null))
      {
        _Employees = base.CreateObjectSet<Employee>("Employees");
      }
      return _Employees;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Bro*_*ass 7

it是当前命令的默认别名ObjectQuery.请参阅Query Builder方法的文档,尤其是Alias部分:

按顺序应用查询构建器方法以构造累积查询命令.这意味着当前的ObjectQuery命令被视为应用当前方法的子查询.

在查询构建器方法中,使用别名引用当前的ObjectQuery命令.默认情况下,字符串"it"是表示当前命令的别名,如下例所示:

int cost = 10;
// Return Product objects with a standard cost
// above 10 dollars.
ObjectQuery<Product> productQuery =
    context.Products
           .Where("it.StandardCost > @cost", new ObjectParameter("cost", cost));
Run Code Online (Sandbox Code Playgroud)

设置ObjectQuery的Name属性时,该值将成为后续方法中的别名.下面的示例通过将ObjectQuery的名称设置为"product"然后在随后的OrderBy方法中使用此别名来扩展前一个示例:

// Set the Name property for the query and then 
// use that name as the alias in the subsequent 
// OrderBy method.
productQuery.Name = "product";
ObjectQuery<Product> filteredProduct = productQuery.OrderBy("product.ProductID");
Run Code Online (Sandbox Code Playgroud)