Delete record via RIA Services in Silverlight
I have a DataGrid in a Silverlight application. This application is using RIA Data Services. My code looks like the following:
<riaControls:DomainDataSource AutoLoad="True"
d:DesignData="{d:DesignInstance my1:Order, CreateList=true}" Height="0"
LoadedData="orderDomainDataSource_LoadedData" Name="orderDomainDataSource"
QueryName="GetOrdersQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:OrderDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<sdk:DataGrid AutoGenerateColumns="True" Height="202" Name="ordersDataGrid"
HorizontalAlignment="Left"
ItemsSource="{Binding ElementName=orderDomainDataSource, Path=Data}">
</sdk:DataGrid>
<Button Content="De开发者_如何学Clete Order" Height="23" Name="deleteButton"
Width="90" Grid.Row="1" HorizontalAlignment="Left" Margin="102,8,12,0"
Click="deleteButton_Click" />
In my code-behind, I have
private void deleteButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (HtmlPage.Window.Confirm("Are you sure you want to delete this order?") == true)
{
}
}
My problem is, I can't figure out how to delete the record from my data source. How do I delete the record that is currently selected in my DataGrid?
Thank you
if (HtmlPage.Window.Confirm("Are you sure you want to delete this order?") == true)
{
DomainDataSource.DataView.Remove(DataGrid.SelectedItem);
DomainDataSource.SubmitChanges();
}
First of all, you can't define your own methods of Insert/Update/Delete -even observing the naming conventions - because the compiler generate a list of errors saying this is a redundant operation that already exists Second, in the client side if you write: DomainDataSource.DataView.Remove(DataGrid.SelectedItem); DomainDataSource.SubmitChanges() you get another error in execution time by saying this entity (DataGrid.SelectedItem) is not included in the entitySet Then What to do ? Why the CRUD Methods geneated can't be called directly ?
精彩评论