locked
generate insert & update method in DomainContext RRS feed

  • Question

  • Hi,

    I have a domaine service with query,update and add operations.

    in the client side, i can see my queries methodes (getUser()) but not my update, add and delete methods !!!

    public void InsertUsager(Usager usager)
            {
                if ((usager.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(usager, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.UsagerBase.AddObject(usager);
                }
            }
    
            public void UpdateUsager(Usager currentUsager)
            {
                this.ObjectContext.UsagerBase.AttachAsModified(currentUsager, this.ChangeSet.GetOriginal(currentUsager));
            }
    
            public void DeleteUsager(Usager usager)
            {
                if ((usager.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(usager, EntityState.Deleted);
                }
                else
                {
                    this.ObjectContext.UsagerBase.Attach(usager);
                    this.ObjectContext.UsagerBase.DeleteObject(usager);
                }
            }

    Why I can't see those methods even if they match the expected signature !!!

    Friday, August 12, 2011 12:33 PM

Answers

  • The Create, Update, and Delete (CUD) methods only exist on the server side, they do not exists on the client. Their existance does control if you can modify the entities client side but they are not directly exposed.

    To Create an entity you create a new Entity and add it to the EntitySet:

    TEntity newTEntity = new TEntity();
    //Set values
    Context.TEntities.Add(newTEntity);

    To Update an entity, you just change the properties of the entity:

    currentTEntity.SomeProperty = someNewValue;

    To Delete an entity, you remove it from the EntitySet:

    Context.TEntities.Remove(currentTEntity);

    When you want to submit the changes to the server, you call Context.SubmitChanges();

    SubmitChanges packages all of the changes into a ChangeSet and sends that to the DomainService's Submit method. Inside the Submi method the DomainService finds the changes in the ChangeSet ands calls the appropriate CUD methods to move those changes into the DAL.

    Friday, August 12, 2011 12:57 PM

All replies

  • The Create, Update, and Delete (CUD) methods only exist on the server side, they do not exists on the client. Their existance does control if you can modify the entities client side but they are not directly exposed.

    To Create an entity you create a new Entity and add it to the EntitySet:

    TEntity newTEntity = new TEntity();
    //Set values
    Context.TEntities.Add(newTEntity);

    To Update an entity, you just change the properties of the entity:

    currentTEntity.SomeProperty = someNewValue;

    To Delete an entity, you remove it from the EntitySet:

    Context.TEntities.Remove(currentTEntity);

    When you want to submit the changes to the server, you call Context.SubmitChanges();

    SubmitChanges packages all of the changes into a ChangeSet and sends that to the DomainService's Submit method. Inside the Submi method the DomainService finds the changes in the ChangeSet ands calls the appropriate CUD methods to move those changes into the DAL.

    Friday, August 12, 2011 12:57 PM
  • I dont understanf what u said abt update ..would you explain it little more??

    Thursday, October 20, 2011 10:58 AM