gpt4 book ai didi

C# LINQ - 找不到 IListSource [Xamarin Forms]

转载 作者:太空宇宙 更新时间:2023-11-03 15:12:20 25 4
gpt4 key购买 nike

我不明白为什么会收到此错误。我正在尝试在 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”行会导致相同的错误:

Reference to type 'IListSource' claims it is defined in 'System', but it could not be found

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

public interface IListSource Member of System.ComponentModel

Summary: Provides functionality to an object to return a list that can be bound to a data source.

Attributes: [System.ComponentModel.TypeConverterAttribute("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataSourceListEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, 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 Forms 具体有关吗?

如果有任何其他信息有帮助,请告诉我。任何关于在何处寻找可能的问题的建议都将不胜感激!

最佳答案

// 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;

关于C# LINQ - 找不到 IListSource [Xamarin Forms],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40581863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com