【问题标题】:C# LINQ - IListSource not found [Xamarin Forms]C# LINQ - 找不到 IListSource [Xamarin 窗体]
【发布时间】:2017-03-27 16:25:09
【问题描述】:

我不明白为什么我会收到此错误。我正在尝试在 Xamarin for Visual Studio 中使用 LINQ for C# 查询本地数据库。

相关代码:

// Query for customers in London.
IQueryable<Customer> custQuery =
    from cust in Customers
    where cust.City == "London"
    select cust;

'where' 行被标记为错误,如果我删除它,'select' 行会导致同样的错误:

对“IListSource”类型的引用声称它是在“系统”中定义的,但是 找不到

VS 的对象浏览器显示 IListSource 包含在 System.ComponentModel 中,我已将其包含在文件头中。

公共接口 IListSource System.ComponentModel 成员

摘要:为对象提供返回列表的功能,该列表可以 绑定到数据源。

属性: [System.ComponentModel.TypeConverterAttribute("System.Windows.Forms.Design.DataSourceConverter, System.Design,版本=2.0.0.0,文化=中性, PublicKeyToken=b03f5f7f11d50a3a"), System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataSourceListEditor, System.Design,版本=2.0.0.0,文化=中性, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing,版本=2.0.0.0,文化=中性, PublicKeyToken=b03f5f7f11d50a3a"), System.ComponentModel.MergablePropertyAttribute(false)]

这里描述了 LINQ 使用 IListSource 的原因: https://msdn.microsoft.com/en-us/library/bb546190%28v=vs.110%29.aspx

添加对 System.ComponentModel.DataAnnotations 和 System.ComponentModel.Composition 的项目引用似乎没有效果。

我是否可能缺少参考资料?这可能与 Xamarin 表单有关吗?

如果有任何其他信息有帮助,请告诉我。任何关于我在哪里寻找可能的问题的指针都非常感谢!

【问题讨论】:

  • 对我来说,你所做的看起来应该只是 system.linq 需要的,但不确定什么时候它的 xamarin
  • Xamarin 版本?您是否尝试更新到最新版本?
  • Xamarin 4.2.0.719 (15694b9) Visual Studio 扩展,支持 Xamarin.iOS 和 Xamarin.Android 的开发。立即下载 4.2.1.58... Xamarin.Android 7.0.1.6 (5a02b03) Visual Studio 扩展以支持 Xamarin.Android 的开发。 Xamarin.iOS 10.2.0.4 (b638977) Visual Studio 扩展,支持 Xamarin.iOS 的开发。
  • 奇怪,我无法重现此问题。将代码添加到 PCL 项目中的新 X.Forms 解决方案会为我提供整个 Linq 语句的 Can not implicitly convert type IEnumarable to IQueryable 错误消息。但是然后通过将 Linq 语句放在括号中并添加 .AsQueryable&lt;Customer&gt;() 来转换为 IQueryable 可以按预期工作。 IOW 我无法从提供的代码中重现此问题。我可能会遗漏一些东西,因为我之前没有真正使用过IQueryable

标签: c# .net visual-studio linq xamarin


【解决方案1】:
// Query for customers in London.
IQueryable<Customer> custQuery =
from cust in Customers
where cust.City == "London"
select cust;

Customers 只是对象,您需要以某种方式指定数据库:

database.Customers

// Query for customers in London.
IQueryable<Customer> custQuery =
from cust in database.Customers
where cust.City == "London"
select cust;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多