开发者

Silverlight -RIA Services-This EntitySet of type <> does not support the 'Add' operation

开发者 https://www.devze.com 2022-12-23 00:01 出处:网络
In Silverlight project I have this exception when I tried to Add a new object to a DataGrid when a button is clicked.

In Silverlight project I have this exception when I tried to Add a new object to a DataGrid when a button is clicked. In the DomainService class.. I know I have to implement the Add operation for the new Entity I'm putting, but how can I do that? I mean I did the class, the get method but how do I do the insert operation, I can't see my class in this.ObjectContext, so to whom I would be adding this new object, I have the next fragments of code:

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();
        }

Plz Help!!


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


Correct, you won't see this.ObjectContext.AddToSisPer. But your ObjectContext exposes EntitySet<SisPer> SisPers. Whenever you call ObjectSet.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.

0

精彩评论

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

关注公众号