Silverlight -RIA 服务 - 此 EntitySet 类型为 <>不支持“添加”手术
在 Silverlight 项目中,当我尝试在单击按钮时将新对象添加到 DataGrid 时,出现此异常。 在 DomainService 类中.. 我知道我必须为要放置的新实体实现添加操作,但我该怎么做呢? 我的意思是我做了类、get 方法,但是如何执行插入操作,我在 this.ObjectContext 中看不到我的类,所以我要向谁添加这个新对象,我有以下代码片段:
public partial class SisPer
{
[Key]
public int Id { get; set; }
public string Nombre_Sistema { get; set; }
public string Nombre_Perfil { get; set; }
public string Nivel { get; set; }
public bool Estatus { get; set; }
}
public IQueryable<SisPer> Get_SisPer()
{
var query =
from per in this.ObjectContext.Cat_Perfil
join sis in this.ObjectContext.Cat_Sistema
on per.Cat_Sistema.Id equals sis.Id
select new SisPer()
{
Id = per.Id,
Nombre_Sistema = sis.Nombre,
Nombre_Perfil = per.Nombre,
Nivel = per.Nivel,
Estatus = per.Estatus
};
return query;
}
public void InsertSisPer(SisPer sisper)
{
?? I can't see this.ObjectContext.AddToSisPer();
}
请帮助!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确,您不会看到 SisPers。每当您调用
this.ObjectContext.AddToSisPer
。但是您的 ObjectContext 公开了 EntitySetObjectSet.Sispers.Add(SisPer sisper)
时,只要您遵循 域服务。例如,在插入操作中添加 Insert-、Add- 或 Create 前缀,用 [Insert] 属性对其进行修饰,传入 SisPer 实体,然后返回 void。Correct, you won't see
this.ObjectContext.AddToSisPer
. But your ObjectContext exposesEntitySet<SisPer> SisPers
. Whenever you callObjectSet.Sispers.Add(SisPer sisper)
, your insert operation will be called automatically provided you follow the conventions described in Domain Services. E.g. prefix your insert operation with Insert-, Add-, or Create, decorate it with the [Insert] attribute, pass in a SisPer entity, and return void.您将需要查看演示模型。合并这两个表有充分的理由吗?它增加了很多工作,您只需公开两个表就可以避免这些工作。如果您不希望某些属性在客户端上可用,您可以对它们使用 ExcludeAttribute。
http:// blogs.msdn.com/deepm/archive/2009/11/20/wcf-ria-services-presentation-model-explained.aspx
You will want to check out the presentation model. Is there a good reason to combine the two tables? It adds a lot of work that you could avoid by just exposing both tables. If you don't want some of the properties to be available on the client you can use the ExcludeAttribute on them.
http://blogs.msdn.com/deepm/archive/2009/11/20/wcf-ria-services-presentation-model-explained.aspx