EF 4 Self Tracking Entities does not work as expected.

Posted by ashraf on Stack Overflow See other posts from Stack Overflow or by ashraf
Published on 2010-01-30T01:14:34Z Indexed on 2011/01/09 16:53 UTC
Read the original article Hit count: 272

I am using EF4 Self Tracking Entities (VS2010 Beta 2 CTP 2 plus new T4 generator). But when I try to update entity information it does not update to database as expected.

I setup 2 service calls. one for GetResource(int id) which return a resource object. the second call is SaveResource(Resource res); here is the code.

    public Resource GetResource(int id)
    {
        using (var dc = new MyEntities())
        {
            return dc.Resources.Where(d => d.ResourceId == id).SingleOrDefault();
        }        
    }

    public void SaveResource(Resource res)
    {
        using (var dc = new MyEntities())
        {
            dc.Resources.ApplyChanges(res);
            dc.SaveChanges();
            // Nothing save to database.
        }      
    }

    //Windows Console Client Calls
    var res = service.GetResource(1);
    res.Description = "New Change"; // Not updating...
    service.SaveResource(res); 

    // does not change anything.

It seems to me that ChangeTracker.State is always show as "Unchanged".

anything wrong in this code?

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about self-tracking-entities