开发者

Domain Service Named Method Update not working

I am using VS 2010 and Silverlight 4 and WCF RIA v1

I am getting a strange error when I try to use a named update method in the domain service.

This is the error:

"Message: Unhandled Error in Silverlight Application *Submit operation failed. Value cannot be null.*Parameter name: original at System.ServiceModel.DomainServices.EntityFramework.ObjectContextExtensions."

Error happens here in the domain service this.ObjectContext.Prospects.AttachAsModified(p, this.ChangeSet.GetOriginal(p));

I have read the change documentation for WCF and I think I am doing everything right.

Could someone please help me to figure out wha is going on?

Cheers

This is the code explanation:

Client

.....

<riaControls:DomainDataSource.DomainContex开发者_开发知识库t>
      <my:MarketingDomainContext />
 </riaControls:DomainDataSource.DomainContext>

.....

<Grid x:Name="LayoutRoot" Background="White">
     <Grid DataContext="{Binding ElementName=comboBoxProspects, Path=SelectedItem}" 
            Name="gdProspects" Margin="10">

....... .......

I grab the Prospects entity from the Grid.

I have tried to call the named update method using both the context declared globally and the update method int Entity.

public partial class MainPage : UserControl
{

    MarketingDomainContext ctx;

    private void dsProspects_LoadedData(object sender, LoadedDataEventArgs e)
    {
          ctx = (MarketingDomainContext)dsProspects.DomainContext;
    }

    private void btnSubmit2_Click(object sender, RoutedEventArgs e)
    {
      //((Prospect)gdProspects.DataContext).CalculateProspectValue(
     //    int.Parse(tbNumber1.Text), int.Parse(tbNumber2.Text));
      var tempProsp = gdProspects.DataContext as Prospect;
      ctx.CalculateProspectValue(tempProsp, int.Parse(tbNumber1.Text), 
         int.Parse(tbNumber2.Text));
        ctx.SubmitChanges();
   }

Domain Service method

[Update(UsingCustomMethod=true)]    
public void CalculateProspectValue(Prospect p, int a, int b)     
{
   p.Comments = "Value = " + a * b;
   // Error happens here
   this.ObjectContext.Prospects.AttachAsModified(p, this.ChangeSet.GetOriginal(p));

 }

 public void UpdateProspect(Prospect currentProspect)    
 {
  this.ObjectContext.Prospects.AttachAsModified(currentProspect,   this.ChangeSet.GetOriginal(currentProspect));

 }


You need to add [RoundTripOriginal] attribute to one of the 'Prospects' members in your metadata that is not the key.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜