RIA Services EntitySet does not support 'Edit' operation

最后都变了- 提交于 2019-11-30 00:37:40

问题


Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created an EF Model (no POCOs), generic repository on top of it and a RIA Service(hosted in an ASP.NET MVC application) and tried to get data from within the ASP.NET MVC application: worked well. Next step: Silverlight client. Got a reference to the RIAService (through its context), queried for all the records of the repository and got them into the SL application as well (using this code sample):

private ObservableCollection<Culture> _cultures = new ObservableCollection<Culture>();
public ObservableCollection<Culture> cultures
{
  get { return _cultures; }
  set
  {
    _cultures = value;
    RaisePropertyChanged("cultures");
  }
}

....

//Get cultures            
EntityQuery<Culture> queryCultures = from cu in dsCtxt.GetAllCulturesQuery()
                                             select cu;
loCultures = dsCtxt.Load(queryCultures);
loCultures.Completed += new EventHandler(lo_Completed);

....

void loAnyCulture_Completed(object sender, EventArgs e)
{
  ObservableCollection<Culture> temp= 
  new ObservableCollection<Culture>loAnyCulture.Entities);
                AnyCulture = temp[0];
}

The problem is this: whenever i try to edit some data of a record (in this example the first record) i get this error: This EntitySet of type 'Culture' does not support the 'Edit' operation.

I thought that i did something weird and tried to create an object of type Culture and assign a value to it: it worked well!

What am i missing? Do i have to declare an EntitySet? Do i have to mark it? Do i have to...what?

Thanks in advance


回答1:


It turns out that in the DomainService class one has to implement (or at least to mark "placeholder methods") as "Edit", "Delete",... eg

[Delete]
public void DeleteCulture(Culture currentCulture)
{
   throw new NotImplementedException("UpdateCulture not Implemented yet");
}
[Insert]
public void InsertCulture(Culture newCulture)
{
   throw new NotImplementedException("InsertCulture not Implemented yet");
}

This way the OrganizationDomainContextEntityContainer class creates an EntitySet with parameter EntitySetOperations.All (meaning that all the CUD operations are available).

Hope it's useful for someone in the future!



来源:https://stackoverflow.com/questions/2445634/ria-services-entityset-does-not-support-edit-operation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!