I built a very simple Silverlight RIA solution, with EF4 in the server side. I added a Named Update method to the DomainService, but I can't use it. The problem is with ChangeSet.GetOriginal(). It returns null :
[EnableClientAccess()]
public class StudentsDomainService : LinqToEntitiesDomainService<Model1Container>
{
[Update(UsingCustomMethod = true)]
public void MyMethod(Student stud, int a, int b)
{
stud.FirstName = (a*b).ToString();
var original = this.ChangeSet.GetOriginal(stud);
// original is null;
this.ObjectContext.StudentSet.AttachAsModified(stud, original); //Exception is thrown
}
.
.
.
}
this is the the xaml codebehind:
public partial class MainPage : UserControl
{
StudentsDomainContext ctx;
Student stud;
public MainPage()
{
InitializeComponent();
ctx = new StudentsDomainContext();
}
private void buttonGet_Click(object sender, RoutedEventArgs e)
{
ctx.Load<Student>(ctx.GetStudentSetQuery()).Completed += new EventHandler(MainPage_Completed);
}
void MainPage_Completed(object sender, EventArgs e)
{
var lo = (sender as LoadOperation<Student>);
stud = lo.Entities.First();
}
private void buttonChange_Click(object sender, RoutedEventArgs e)
{
stud.MyMethod(3, 6);
ctx.SubmitChanges();
}
}
It's important to note that when I using a simple Update via the auto generated CRUD everything works.