gpt4 book ai didi

c# - Microsoft.OData.Client.DataServiceCollection 异常 : Entity set name has not been provided for an entity of type

转载 作者:行者123 更新时间:2023-12-02 04:29:02 28 4
gpt4 key购买 nike

我在使用 Microsoft.OData.Client.DataServiceCollection 实例并对其调用 Load(...) 或 Add(...) 时遇到以下异常:尚未为类型 的实体提供实体集名称。

例如:

DataServiceCollection<TEntity> collection = 
new DataServiceCollection<TEntity>(_repoDataServiceQuery);
collection.Load(entity);

关于我错过了什么以避免异常的任何建议?

最佳答案

_repoDataServicerQuery 是实体集的查询还是从服务器获取的实体的 IEnumerable ?在这种情况下,您不需要在构造 DataServiceCollection 时提供实体集名称,它会为您找到并设置它,因为查询或项目中包含足够的信息。否则,如果您只想在一个空的 DataServiceCollection 中添加或加载实体,则需要设置实体集名称以告诉它要添加到哪个实体集或从中加载。例如:

DataServiceCollection<Customer> customers =
new DataServiceCollection<Customer>(context, "Customers"/*entityset name*/, null, null);
var customer = new Customer();
customers.Add(customer);

构造函数是

public DataServiceCollection(DataServiceContext context, string entitySetName, Func<EntityChangedParams, bool> entityChangedCallback, Func<EntityCollectionChangedParams, bool> collectionChangedCallback);

最后两个 Func 可以简单地为 null

关于c# - Microsoft.OData.Client.DataServiceCollection<T> 异常 : Entity set name has not been provided for an entity of type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24665334/

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