locked
WebDataContext does not reload new data after deletion RRS feed

  • Question

  • Hi Guys,

     

    I'm deleting some entities successfully using DeleteObject. If someone now creates a new record in the database with exactly the same primary key (compound or single field) and you try to retrieve the new value the data is downloaded but not tracked by the WebDataContext. The AttachObject method may be a possible workaround for the time being but only for entities with single field primary keys due to an issue mentioned in an earlier outstanding post.

     

    Thanks for any info

    Friday, March 14, 2008 5:13 PM

Answers

All replies

  •  

    Can you see if the object is still being tracked in the context after you call SaveCanges()?

     

    Although this scenario in general (PKs must be unique for Entities) is not supported, this should probably work as long as you persist the deletion to the store before the new one is created.

     

     

    Friday, March 14, 2008 8:19 PM
    Moderator
  • Thanks for the reply Andrew,

     

    The object is not being tracked at all, either the detached, deleted or newly created one. I haven't tried to create a new object via WebDataContext, just directly on the database so I don't know if the WebDataContext will complain if a new object with a Primary Key it was tracking before deletion is added directly to it via AddObject.

     

    I've been checking the AtomPub via a web browser as well as the database directly and all deletions are going through just fine.

     

    If it helps, I've been using the following extension method to see if something is being tracked or not:

     

    Code Snippet

    public static class ResourceHelpers

    {

    public static System.Nullable<ResourceObject> GetResource(this WebDataContext webContext, object needle)

    {

    System.Nullable<ResourceObject> res = null;

     

    try

    {

    res = (

    from r in webContext.Resources

    where r.Resource == needle

    select r

     ).Single();

    }

    catch (Exception) { }

     

    return res;

    }

     

    public static bool IsTracked(this WebDataContext webContext, object needle)

    {

    try

    {

    ResourceObject res = (

    from r in webContext.Resources

    where r.Resource == needle

    select r

     ).Single();

    return true;

    }

    catch (Exception)

    {

    return false;

    }

    }

    }

     

    Saturday, March 15, 2008 10:38 AM
  • Hi,

     

    We just released a new pre-release version of data services (Beta 1).  We have changed a number of things in both the client and the server since the Dec 2007 CTP, can you give this a spin with the updated bits?

     

    My blog has links to downloads, etc here: http://blogs.msdn.com/astoriateam/archive/2008/05/12/ado-net-data-services-framework-beta-1-is-live.aspx

     

    Thanks

    Mike

     

    Sunday, May 18, 2008 7:54 PM
  • I'm currently away from our test database so am trying to figure out a way to quickly recreate it using the data available within the Entity Model we're using (either from SSDL or CSDL). Once I do I'll update this with my findings.

     

    I've already created a thread requesting some advice on creating a database from a model in the EF forums and any ideas will be appreciated.

    Monday, May 19, 2008 8:47 AM
  • Please give this a try with our updated Beta 1 release.  Also, note the merge options on the DataServiceContext class will help to control what occurs when the same object (same == same key in this context) is queried that is already tracked locally.

     

     

    download is here: http://www.microsoft.com/downloads/details.aspx?FamilyId=8C36ACA4-E947-4760-9B05-93CAC04C6F87&displaylang=en

    Wednesday, June 18, 2008 4:47 AM
  •  

    The RTM version of the product has been released to give this a spin with that includes a number of bug fixes in our client state mgt: http://msdn.microsoft.com/en-us/vstudio/cc533448.aspx
    Friday, August 15, 2008 4:36 PM