0

プロジェクトをセットアップしました。これは、ASP.NetサイトでホストされているSilverlightクライアントアプリケーションです。SQLServerデータベースと通信するためのADO.NetEntityFrameworkと、通信のためのADO.NetDataServiceがあります。非同期CRUDSilverlightInsertをデータベースで機能させるのに問題があります。最初のメソッドは正常に起動し、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

エンティティのアクセス権を確認する必要がある場合があります。チュートリアルのステップの1つで、これは構成されていますが、場合によっては「AllRead」に設定されています。エンティティが書き込みアクセスを許可していることを確認する必要があります。

于 2009-09-09T11:25:25.833 に答える
0

現在、問題が発生している場所を正確に特定することを困難にする多くのレイヤーがあります。

WindowsアプリからEFモデルに直接クエリを呼び出すと、機能しますか?そうでない場合は、モデルに問題がある可能性があります。

ブラウザからADO.NETデータサービスにアクセスできますか?

サービスをホストしているサーバーにclientaccesspolicy.xmlファイルがありますか?

file://の場所ではなく、http://の場所からSilverlightアプリを実行していますか?

于 2009-09-09T20:14:44.357 に答える