Silverlight - Crud Insert意外失败?

时间:2009-09-09 11:21:37

标签: silverlight crud

我有一个项目设置 - 它是一个托管在ASP.Net站点的Silverlight客户端应用程序。它有一个ADO.Net实体框架,用于与SQL Server数据库和ADO.Net数据服务进行通信。 我在使用异步CRUD Silverlight插件在我的数据库上工作时遇到了一些麻烦。第一种方法触发罚款并传入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数据库的this Microsoft教程中解除并修改。本教程中的所有其他代码示例都可以正常工作,因为我的数据库与Northwind的结构类似。到目前为止,我已经能够实现RUD,但不能实现CRUD。

有人能说清楚这个问题吗?

非常感谢!

2 个答案:

答案 0 :(得分:1)

您可能需要查看您的实体访问权限。在本教程的one of the steps中,您引用了此配置但在某些情况下设置为“AllRead”。您需要确保您的权限允许写访问权。

答案 1 :(得分:0)

现在有很多层层很难确切地说出问题的确切位置。

当您从Windows应用程序直接调用查询到EF模型时它是否有效?如果没有,你的模型可能会出现问题。

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

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

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

相关问题