RIA 服务 EntitySet 不支持“编辑”;手术

发布于 2024-08-25 03:23:50 字数 1270 浏览 8 评论 0原文

在 RIA Services (VS2010Beta2) 中迈出第一步时,我遇到了这个问题: 创建了一个 EF 模型(无 POCO)、其上的通用存储库和一个 RIA 服务(托管在 ASP.NET MVC 应用程序中),并尝试从 ASP.NET MVC 应用程序中获取数据:效果很好。 下一步:Silverlight 客户端。获取对 RIAService 的引用(通过其上下文),查询存储库的所有记录并将它们放入 SL 应用程序(使用此代码示例):

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];
}

问题是这样的:每当我尝试编辑记录的一些数据(在本例中是第一条记录),但出现此错误: 此“文化”类型的 EntitySet 不支持“编辑”操作。

我认为我做了一些奇怪的事情,并尝试创建一个 Culture 类型的对象并为其分配一个值:它运行良好!

我缺少什么?我必须声明一个 EntitySet 吗?我必须标记它吗?我必须……什么吗?

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手长情犹 2024-09-01 03:23:50

事实证明,在 DomainService 类中,必须实现(或至少将“占位符方法”标记为“编辑”、“删除”,...例如,

[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");
}

OrganizationDomainContextEntityContainer 类通过这种方式创建一个带有参数 EntitySetOperations.All 的 EntitySet(意味着所有 CUD 操作都可用)。

希望它对将来的人有用!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文