0

我有一个项目设置 - 它是托管在 ASP.Net 站点中的 Silverlight 客户端应用程序。它具有用于与 SQL Server 数据库通信的 ADO.Net 实体框架和用于通信的 ADO.Net 数据服务。我在让我的异步 CRUD Silverlight Insert 在我的数据库上工作时遇到了一些麻烦。第一种方法触发良好并传入 URI。但是当“OnClientJobQueryComplete”方法触发时,它失败了大约 5 行,我不明白为什么。异常显示“处理此请求时发生错误”。

private void addStuff_Click(object sender, RoutedEventArgs e)
    {
        // Define a URI that returns the product with the specified ID.
        Uri jobrefUri = new Uri(svcContext.BaseUri.AbsoluteUri
            + "/ClientJob(" + this.jobref.Text + ")");

        // Begin a query operation retrieve the Product object 
        // that is required to add a link to the new Order_Detail.
        svcContext.BeginExecute<ClientJob>(jobrefUri,
            OnClientJobQueryCompleted,null);
    }

    private void OnClientJobQueryCompleted(IAsyncResult result)
    {
        // Use the Dispatcher to ensure that the 
        // asynchronous call returns in the correct thread.
        Dispatcher.BeginInvoke(() =>
        {
            // Get the Product returned by the completed query.
            IEnumerable<ClientJob> queryResult =
                svcContext.EndExecute<ClientJob>(result);//**TRIES THIS BUT FAILS HERE

            ClientJob returnedClientJob = queryResult.First();

            // Get the currently selected order. (Create new Guid since not Northwind)
            Guid g = Guid.NewGuid();

            // Create a new Order_Details object with the supplied FK values.
            Job newItem = Job.CreateJob(g);
            //Job newItem = Job.CreateJob(g, returnedClientJob.JobRef);

            jobsBindingCollection.Add(newItem);

            // Add the new item to the context.
            svcContext.AddToJob(newItem);

            //// Add the relationship between the order and the new item.
            //currentOrder.Order_Details.Add(newItem);
            //svcContext.AddLink(currentOrder, "Order_Details", newItem);

            //// Set the reference to the order and product from the item.
            //newItem.Orders = currentOrder;
            //svcContext.SetLink(newItem, "Orders", currentOrder);

            // Add the relationship between the product and the new item.
            returnedClientJob.Job.Add(newItem);
            svcContext.AddLink(returnedClientJob, "Job", newItem);

            // Set the reference to the product from the item.
            newItem.ClientJob = returnedClientJob;
            svcContext.SetLink(newItem, "ClientJob", returnedClientJob);
        }
        );
    }

代码是从使用 Northwind 数据库的 Microsoft 教程中提取和修改的。本教程中的所有其他代码示例都可以正常工作,因为我的数据库与 Northwind 的结构相似。到目前为止,我已经能够实现 RUD,但不能实现 CRUD。

任何人都可以阐明这个问题吗?

非常感谢帮助!

4

2 回答 2

1

您可能需要查看您的实体访问权限。在您引用的教程的步骤之一中,它已配置,但在某些情况下设置为“AllRead”。您需要确保您的实体允许写访问。

于 2009-09-09T11:25:25.833 回答
0

现在有很多层次使得很难准确地判断问题发生在哪里。

当您从 Windows 应用程序直接向 EF 模型调用查询时,它是否有效?如果不是,则您的模型可能有问题。

您可以从浏览器访问 ADO.NET 数据服务吗?

托管服务的服务器上是否有 clientaccesspolicy.xml 文件?

您是从 http:// 位置而不是 file:// 位置运行 silverlight 应用程序吗?

于 2009-09-09T20:14:44.357 回答