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();
}
これに関連するかもしれませんか? http://blog.davidyack.com/journal/2009/7/21/ria-services-domaindatasourcedata-not-updating.html –
あなたのデータスクラップに不一致がある場合、私のケースではこの種の問題が発生します。データベースにnull(NULL)のchar(1)フィールドがありましたが、データ・クリップのフィールドはNullable false – Martin