The Elephant and the Silverlight

Thoughts and analysis of Silverlight for business applications

Page List

    Bug in the Create DomainService wizard

    In a previous blog post I documented an undocumented breaking change in the DomainService wizard. It turns out that it is really a bug.

     

    When you create a DomainService using the July .NET RIA Services you would get an update that looks like this:

    public void UpdateMyEntity(MyEntity currentMyEntity)
    {
        this.ObjectContext.AttachAsModified(currentMyEntity, this.ChangeSet.GetOriginal(currentMyEntity));
    }

    The new version gives you a version that looks like this:

    public void UpdateMyEntity(MyEntity currentMyEntity)
    {
        if ((currentMyEntity.EntityState == EntityState.Detached))
        {
            this.ObjectContext.AttachAsModified(currentMyEntity, this.ChangeSet.GetOriginal(currentMyEntity));
        }
    } 

    It turns out that the new version is a mistake, not a change that was undocumented in the breaking changes document, and it is causing major problems for people. The recommendation is that all Updates should be modified to remove the If check so that the resulting method looks like the original .NET RIA Services version.


    Categories: RIA Services
    Permalink | Comments (7) | Post RSSRSS comment feed

    Comments

    kilativ United States

    Monday, December 07, 2009 12:18 PM

    kilativ

    I wish i read this before. spent 2 hours fixing this yesterday. Somehow it's a problem only when you save more than 2 entities at once. The first one is ok, but the second one always comes as "Unchanged" even though it's modified on the client side.

    Rui Craveiro Portugal

    Friday, December 11, 2009 12:27 PM

    Rui Craveiro

    I am so sorry I had not noticed this post before... Lost a few hours before coming here. You saved my day. Thank you!!!

    alvin Singapore

    Thursday, March 18, 2010 4:15 AM

    alvin

    kilativ - i got exactly same problem as yours... great life saver this post! but how nuts is microsoft to miss this?

    Greg Hollywood United States

    Saturday, April 17, 2010 7:50 PM

    Greg Hollywood

    The current version of Ria is giving me this.  Is this still a bug or is it ok now?

    if ((contactEntity.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(contactEntity, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.ContactEntities.AddObject(contactEntity);
                }

    Greg Hollywood United States

    Saturday, April 17, 2010 7:53 PM

    Greg Hollywood

    Note that the code in my comment above is for the Add, not the update.  The update is giving the non-buggy code as you note.

    Greg

    The Elephant and the Silverlight

    Tuesday, July 13, 2010 9:51 AM

    trackback

    Undocumented DomainService Wizard change in WCF RIA Services

    Undocumented DomainService Wizard change in WCF RIA Services

    John Rugby United Kingdom

    Friday, July 30, 2010 6:55 AM

    John Rugby

    Thanks, you just saved me from going around in circles with this!

    Add comment


    (Will show your Gravatar icon)

      Country flag

    Click to change captcha
    biuquote
    • Comment
    • Preview
    Loading