1

RIAサービスでSilverlight 3アプリケーションを開発中です。私はアプリを稼働させているが、何らかの理由でデータを読み取っているだけで、変更をコミットしていない。Silverlight 3 + RIA Servicesデータコミットの問題

私が見たオンラインの例のほとんどは、Linq2Entitiesを使用しています。

[EnableClientAccess] 
public class FooService : LinqToSqlDomainService<FooDataContext> 
{ 
    [RequiresAuthentication()] 
    public IQueryable<UserProfile> GetUserProfiles() 
    { 
     return this.Context.UserProfiles; 
    } 

    [RequiresAuthentication()] 
    public void InsertUserProfile(UserProfile profile) 
    { 
     this.Context.UserProfiles.InsertOnSubmit(profile); 
    } 

    [RequiresAuthentication()] 
    public void UpdateUserProfile(UserProfile currentProfile) 
    { 
     this.Context.UserProfiles.Attach(currentProfile, true); 
    } 

    [RequiresAuthentication()] 
    public void DeleteUserProfile(UserProfile profile) 
    { 
     this.Context.UserProfiles.Attach(profile, profile); 
     this.Context.UserProfiles.DeleteOnSubmit(profile); 
    } 
} 

はここで私が使用しているXAMLの抜粋です:

我々はLinq2SQL(。私たちのデータモデルは、AS-で抽象化することなく、かなり良いです)

ここでサービスの抜粋ですを使用しています

<dataControls:DataForm x:Name="_profileForm" AutoGenerateFields="False" CommandButtonsVisibility="Commit" AutoEdit="True" > 
       <dataControls:DataForm.EditTemplate> 
        <DataTemplate> 
         <StackPanel Orientation="Vertical"> 
          <dataControls:DataField Label="Username"> 
           <TextBox Text="{Binding UserName, Mode=TwoWay}" /> 
          </dataControls:DataField> 

          <dataControls:DataField Label="First Name"> 
           <TextBox Text="{Binding FirstName, Mode=TwoWay}" /> 
          </dataControls:DataField> 

          <dataControls:DataField Label="Last Name"> 
           <TextBox Text="{Binding LastName, Mode=TwoWay}" /> 
          </dataControls:DataField> 

          <dataControls:DataField Label="Password"> 
           <PasswordBox Password="{Binding Password, Mode=TwoWay}"/> 
          </dataControls:DataField> 

          <!-- [Snip] --> 

          </dataControls:DataField> 
         </StackPanel> 
        </DataTemplate> 
       </dataControls:DataForm.EditTemplate> 
      </dataControls:DataForm> 

そしてここでは、Silverlightのページの抜粋です:

public partial class Profile : Page 
{ 
    private FooContext _dataContext; 

    public Profile() 
    { 
     InitializeComponent(); 
     this._dataContext = new FooContext(); 
    } 

    protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     LoadOperation<UserProfile> loadOperation = this._dataContext.Load<UserProfile>(this._dataContext.GetUserProfilesQuery()); 
     loadOperation.Completed += new EventHandler(this.LoadOperation_Completed); 
    } 

    private void LoadOperation_Completed(object sender, EventArgs e) 
    { 
     // Bind the RIA data to the controls 
     LoadOperation<UserProfile> loadOperation = sender as LoadOperation<UserProfile>; 
     this._profileForm.EditEnded += new EventHandler<DataFormEditEndedEventArgs>(ProfileForm_EditEnded); 
     this._profileForm.ItemsSource = loadOperation.Entities; 
     this._profileForm.CurrentIndex = 0; 
    } 

    private void ProfileForm_EditEnded(object sender, DataFormEditEndedEventArgs e) 
    { 
     this._dataContext.SubmitChanges(); 
    } 

答えて

0

みんなありがとう!私は、これがうまくいくために必要なことを結論づけました。なぜ私はちょうどまだ、しかしこれが問題を解決したのか分かりません。

[RequiresAuthentication()] 
public void UpdateUserProfile(UserProfile currentProfile) 
{ 
    UserProfile originalProfile = this.ChangeSet.GetOriginal(currentProfile); 
    this.Context.UserProfiles.Attach(currentProfile, originalProfile); 
} 

やれやれ:私は、次のように更新方法を変更しました。今は元のバージョンを取得する前にエンティティをアタッチできなかった理由を理解するだけです。

もう一度皆様に感謝します。

+0

これに関連するかもしれませんか? http://blog.davidyack.com/journal/2009/7/21/ria-services-domaindatasourcedata-not-updating.html –

+0

あなたのデータスクラップに不一致がある場合、私のケースではこの種の問題が発生します。データベースにnull(NULL)のchar(1)フィールドがありましたが、データ・クリップのフィールドはNullable false – Martin

1

誤差があり、何もしませんSubmitChangesに電話するとどうなりますか?

は、ここで私が試してみたものです:サーバーのCRUDメソッドの

  1. ブレークポイントの設定は、それらが呼び出されていることを確認します。
  2. that can cause a new instance to be created rather than an update of the existing entityのように、いずれの値にもNULLを渡していないことを確認してください。
  3. エラーをチェックするためにOnSubmitCompletedイベントを追加しようとします。サンプルコード(from this PDF):

    this._dataContext.SubmitChanges(OnSubmitCompleted, null); 
    
    private void OnSubmitCompleted(SubmitOperation so) 
    { 
         if (so.Error != null) 
         { 
           string message = so.Error.Message; 
           if (so.EntitiesInError.Any()) 
           { 
             message = string.Empty; 
             Entity entityInError = so.EntitiesInError.First(); 
             if (entityInError.Conflict != null) 
             { 
               EntityConflict conflict = entityInError.Conflict; 
               foreach (EntityConflictMember cm in 
                          conflict.MemberConflicts) 
               { 
                 message += string.Format( 
                   "Member '{0}' in conflict: Current: {1}, 
                         Original: {2}, Store: {3}", 
                   cm.PropertyName, cm.CurrentValue, 
                   cm.OriginalValue, cm.StoreValue); 
               } 
             } 
             else if (entityInError.ValidationErrors.Any()) 
             { 
               message += "\r\n" + 
                entityInError.ValidationErrors.First().Message; 
             } 
           } 
           MessageBox.Show(message, "Submit Failed", MessageBoxButton.OK); 
         } 
    } 
    
+0

1.私はブレークポイントを設定し、それはupdateメソッドを呼び出しています。 2. nullは渡されていません(新しいレコードはDBに表示されません)。 3.そのイベントとso.Error = nullが追加されました。 Silverlightクライアントの出力は正常です。私はDataGridを追加し、それはデータフォームからの変更を反映します。 私はこのサービスで次のことをテストして、DBに書かれた問題ではないことを確認しています。 var profile =(Context.UserProfilesのプロファイルから profiles.DBPrimaryKey == 1 profilesを選択してください。 ) 。最初(); profile.LastName = "変更済み"; コンテキスト。SubmitChanges(); –

+0

現在の私の容疑者は、ドメインサービスのUpdateUserProfile()メソッドですが、変更なしで複数のバリエーションを試しました。それが呼び出されている、私はそれを確認しました。 –

2

全く[RequiresAuthentication]変化挙動を削除していますか?

また、設定ファイル、特にHttpHandlerの宣言動詞(GET、POST)がチェックされます。

(血まみれのミートアップのメッセージリスト - 私は初心者くさいとしての日のための私の3メッセージ制限をヒット):ヘルプのためのP

関連する問題