Properties 在OData服务中更新和插入

Properties 在OData服务中更新和插入,properties,insert,odata,Properties,Insert,Odata,我有一个Xamarin.Forms Visual Studio解决方案,我在其中安装了带有NuGet的“Simple.OData.Client”包。我有一个OData服务的URI,我想从表“Persons”中加载项,表中的基本元素类型是“Person”,其中包含类“Customer”的实例,该类从类“Person”继承而来,我在打开附加“/$metadata”的URI时可以看到这一点 <Schema xmlns="http://schemas.microsoft.com/ado/2009/

我有一个Xamarin.Forms Visual Studio解决方案,我在其中安装了带有NuGet的“Simple.OData.Client”包。我有一个OData服务的URI,我想从表“Persons”中加载项,表中的基本元素类型是“Person”,其中包含类“Customer”的实例,该类从类“Person”继承而来,我在打开附加“/$metadata”的URI时可以看到这一点

<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" Namespace="A">
  ...
  <EntityType Name="Person" Abstract="true">
  ...
  <EntityType Name="Customer" BaseType="A.Person">
  ...
  <EntityContainer Name="Model" m:IsDefaultEntityContainer="true">
    ...
    <EntitySet Name="Persons" EntityType="A.Person"/>
    ...
我从数据表中加载项:

System.Collections.Generic.IEnumerable<System.Collections.Generic.IDictionary<string, object>> persons = await clientSimple.For("Persons").FindEntriesAsync();
只要我只更新在“Person”实体类型中定义的属性,但尝试修改在“Customer”实体类型中添加的属性会引发异常,这一点就行得通:

await clientSimple.For("Persons").Key(1).Set(new { FirstName = "Johnny", SalesPerson = "..." }).UpdateEntryAsync();

[Simple.OData.Client.UnresolvableObjectException] No property or association found for [SalesPerson].
尝试插入新项目也会失败:

var newObjectCreated = await clientSimple.For("Persons").Set(new { FirstName = "...", ... }).InsertEntryAsync();

[Simple.OData.Client.WebRequestException] Internal Server Error

如何解决此问题,以便更新所有属性并插入新项目?

有几个信息源可能对您有用。首先,我建议您查看Simple.OData.Client wiki页面,特别是提供如何修改数据示例的页面:

然后,您可以从项目测试中获得大量示例,例如:

如果您想使用类型化语法(我建议),您应该自己定义实体类型,目前Simple.OData.Client没有任何实体类型生成实用程序

await clientSimple.For("Persons").Key(1).Set(new { FirstName = "Johnny" }).UpdateEntryAsync();
await clientSimple.For("Persons").Key(1).Set(new { FirstName = "Johnny", SalesPerson = "..." }).UpdateEntryAsync();

[Simple.OData.Client.UnresolvableObjectException] No property or association found for [SalesPerson].
var newObjectCreated = await clientSimple.For("Persons").Set(new { FirstName = "...", ... }).InsertEntryAsync();

[Simple.OData.Client.WebRequestException] Internal Server Error