在Windows Phone上通过odata添加实体时出现NotSupportedException

时间:2011-01-23 01:43:41

标签: windows-phone-7 odata

我在Windows Phone 7应用程序中使用odata客户端生成器(DataSvcUtil.exe)。检索实体和集合就像更新现有实体一样好。但是当我尝试添加一个新实体时,我得到一个 NotSupportedException 。这是我的代码。

private void Button_Click(object sender, RoutedEventArgs e)
    {
        Drinks d =new Drink();
        d.BarCode = "1234567890";
        d.Description = "Test Drink";
        d.Quantity = -1;
        context.AddToDrinks(d);
        context.BeginSaveChanges(SaveChangesOptions.Batch, OnChangesSaved, context);       
    }

 private void OnChangesSaved(IAsyncResult result)
    {
        Dispatcher.BeginInvoke(() =>
        {
            try
            {
                var something = result.AsyncState;

                context = result.AsyncState as DrinkTrackerModelContainer;

                // Complete the save changes operation and display the response.

                ShowSaveResponse("Drink Logged!", context.EndSaveChanges(result));
            }
            catch (DataServiceRequestException ex)
            {
                ShowSaveResponse("Error Logging Drink", ex.Response);

            }
            catch (InvalidOperationException ex)
            {
                ShowSaveResponse(ex.Message, null);

            }

        }
        );
    }

一旦调用了EndSaveChanges,我就会得到

NotSupportedException异常。

编辑:我使用了fiddler并且看到我实际上从服务中获得了一个不同的例外。该异常数据未在调试器中显示。一旦我更正了实际异常,插入工作正常。

2 个答案:

答案 0 :(得分:0)


 我认为你有第一次机会异常启动,这导致客户端库抛出的内部异常作为异常浮出水面。尝试在VS的“例外”菜单中关闭First Chance Exceptions并运行该应用程序。

答案 1 :(得分:0)

正如您在编辑中提到的,NotSupportedException是一个红色的鲱鱼。我认为,在调试手机应用程序时,即使您已清除设置中断未处理的CLR异常,也会遇到NotSupportedException。

如果继续(F5),您将遇到实际的DataServiceRequestException异常。如果它没有足够的信息来调试它,您可以按照本文中的步骤获取异常中的更多详细信息:http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx

我昨天遇到了同样的问题,在按照博客中的步骤后,我能够成功调试问题。