关于WCF RIA Service 删除操作的有关问题?先多谢了
关于WCF RIA Service 删除操作的问题?请教各位,先谢谢了
silverlight4 + sql2008 +.net2010
1、添加了Movie的ADO.NET数据实体类型
2、添加了Movie的DomainService类
3、拖拽了MovieDomainContext到主页
4、想进行删除操作,以下是代码,删除后在this.movieCtx.Movies.Remove(movie)处抛出错误:
the specified entity is not contained in this entityset.
请教什么地方写错了?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;
using SLA20131012.Web;
namespace SLA20131012
{
public partial class MainPage : UserControl
{
private MovieDomainContext movieCtx = new MovieDomainContext();
public MainPage()
{
InitializeComponent();
bt_del.Click += new RoutedEventHandler(bt_del_Click);
}
private void bt_del_Click(object sender, RoutedEventArgs e)
{
Movie movie = movieDataGrid.SelectedItem as Movie;
this.movieCtx.Movies.Remove(movie); //此处抛出错误
this.movieCtx.SubmitChanges();
}
private void movieDomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)
{
if (e.HasError)
{
System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
e.MarkErrorAsHandled();
}
}
}
}


------解决方案--------------------
我是改成这样成功的:
silverlight4 + sql2008 +.net2010
1、添加了Movie的ADO.NET数据实体类型
2、添加了Movie的DomainService类
3、拖拽了MovieDomainContext到主页
4、想进行删除操作,以下是代码,删除后在this.movieCtx.Movies.Remove(movie)处抛出错误:
the specified entity is not contained in this entityset.
请教什么地方写错了?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;
using SLA20131012.Web;
namespace SLA20131012
{
public partial class MainPage : UserControl
{
private MovieDomainContext movieCtx = new MovieDomainContext();
public MainPage()
{
InitializeComponent();
bt_del.Click += new RoutedEventHandler(bt_del_Click);
}
private void bt_del_Click(object sender, RoutedEventArgs e)
{
Movie movie = movieDataGrid.SelectedItem as Movie;
this.movieCtx.Movies.Remove(movie); //此处抛出错误
this.movieCtx.SubmitChanges();
}
private void movieDomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)
{
if (e.HasError)
{
System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
e.MarkErrorAsHandled();
}
}
}
}
------解决方案--------------------
我是改成这样成功的:
<Grid x:Name="LayoutRoot" Background="White">
<Button Content="删除" Height="23" HorizontalAlignment="Left" Margin="12,208,0,0" Name="bt_del" VerticalAlignment="Top" Width="75" Click="bt_del_Click" />
<sdk:DataGrid AutoGenerateColumns="True" Height="190" HorizontalAlignment="Left" ItemsSource="{Binding ElementName=movieDomainDataSource, Path=Data}" Margin="12,12,0,0" Name="movieDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="164"/>
</Grid>
namespace SLA20131012
{
public partial class MainPage : UserControl
{
private MovieDomainContext movieCtx = new MovieDomainContext();
public MainPage()
{
InitializeComponent();
LoadOperation<Movie> loadMovies = movieCtx.Load(movieCtx.GetMovieQuery());
loadMovies.Completed += loadMovies_Completed;