Hello,
I'm working on a Silverlight 3 app with RIA Services. I've got the app running but for some reason it's only reading data, not committing changes.
Most of the online examples I've seen use Linq2Entities; we're using Linq2SQL (our data model is pretty good as-is without abstraction.)
Here's a snippet of the Service:
[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);
}
}
Here's a snippet of the XAML I'm using:
<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>
And here's a snippet of the Silverlight page:
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();
}