【问题标题】:Could not find an implementation of the query pattern for source type 'object'. 'Select' not found找不到源类型“对象”的查询模式的实现。未找到“选择”
【发布时间】:2017-06-23 04:53:43
【问题描述】:

我试图多次使用同一个 linq 对象,但它抛出了上述错误。这是我的代码。错误在

var GridData = (from x in GridValue select new { x.EmployeeID, x.LastName, x.FirstName, x.HireDate, x.HomePhone });

这一行


public static  object GetData() {
    PopulateGridDataContext populateGridContext = new PopulateGridDataContext();
    var data = from x in populateGridContext.Employees select x;
    return data;
}

protected void Button2_Click(object sender, EventArgs e) {
    //PopulateGridDataContext pgdc = new PopulateGridDataContext();
    var GridValue = WorkingWithLinq.GetData();
    //var data = from x in pgdc.Employees select x;
    var GridData = (from x in GridValue select new { x.EmployeeID, x.LastName, x.FirstName, x.HireDate, x.HomePhone });
    GridView1.DataBind();
}

【问题讨论】:

  • 错误出现在 var GridData = (from x in GridValue select new { x.EmployeeID, x.LastName, x.FirstName, x.HireDate, x.HomePhone });这一行

标签: c# linq object


【解决方案1】:

GetData 方法返回 object,其中不包含 linq 扩展方法。尝试返回或投射到IEnumerable<Employee>

我猜你的物品是员工。您应该能够将鼠标悬停在 data 变量上以查看类型是什么。使用该类型作为返回值。

【讨论】:

  • 谢谢@BillTarbell ..我通过将数据转换为 iqueryable 得到了结果 .. 通过添加这一行 var GridValue = WorkingWithLinq.GetData() as IQueryable;
  • 太棒了。我很高兴能帮到你。如果您认为这是您问题的答案,请将其标记为答案,以便其他人知道并给予认可。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-18
  • 2015-09-23
  • 2013-02-06
  • 2010-11-10
  • 1970-01-01
  • 1970-01-01
  • 2018-02-24
相关资源
最近更新 更多