【问题标题】:OdataClient SaveChanges doesn't work and results an empty Microsoft.OData.Client.DataServiceResponseOdataClient SaveChanges 不起作用并导致空 Microsoft.OData.Client.DataServiceResponse
【发布时间】:2015-09-08 14:35:22
【问题描述】:

由于一些扩展,我封装了odata容器:

public class Connector
{
    public string apiKey{get;set;}

    public  Connector(string apiKey)
    {
        this.apiKey = apiKey;
    }

    public Default.Container Get()
    {
        Default.Container container = new Default.Container(new Uri("http://documents.omnisoftonline.be/odata"));
        container.BuildingRequest += container_BuildingRequest;
        return container;
    }

    /// <summary>
    /// When fetching a single Document, you can enable this method to including fetch the binary data
    /// </summary>
    /// <param name="container"></param>
    /// <returns></returns>

    internal bool doIO = false;
    internal void container_BuildingRequest(object sender, BuildingRequestEventArgs e)
    {
        e.Headers.Add("X-ApiKey", apiKey);

        if (doIO && e.RequestUri.ToString().Contains("/Documents"))
        {
            e.RequestUri = new Uri(e.RequestUri.ToString() + (e.RequestUri.Query.Contains("?") ? "&" : "?") + "doIO=true");
        }


        this.container_BuildingRequest(sender, e);
    }
}

当我使用我的 .dll(使用 Connector 类)时,我得到一个空结果(状态码 = -1,没有标题,...)

这就是我调用 DLL 的方式

 documentsConnector.Get().AddToDocuments(docToCreate);
 var serviceResponse = documentsConnector.Get().SaveChanges(Microsoft.OData.Client.SaveChangesOptions.None); //tried several options
 foreach(var operationResponse in serviceResponse)
 {
      Console.WriteLine("Response: {0}", operationResponse.StatusCode); //no operationResponses, so this isn't executed
 }

这可能是因为我的对象无效。但奇怪的是我没有看到任何验证发生......

关于如何传播 SaveChanges() 或预验证(在提交之前)实体的任何想法?帖子没有发生(用 Fiddler 检查)

【问题讨论】:

  • FirstOrDefault 有效(获取实体): var docToShow = documentsConnector.Get().Documents.Where(el => el.Id == options.key.Value).FirstOrDefault();跨度>
  • 我注意到 System.ComponentModel.INotifyPropertyChanged 属性没有触发...如果有帮助的话

标签: asp.net-web-api entity-framework-6 odata asp.net-web-api2 odatacontroller


【解决方案1】:

我的包装类每次都会创建一个新容器,因此实体会从 Default.Container 中删除

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 2017-05-09
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    相关资源
    最近更新 更多