0

I am using EF with Oracle..

I have a test that will run this bit of code

using (var ctx = new Entities())
{
 ctx.SOMEOBJECTSESSIONs.Add(
    new SOMEOBJECTSESSION()
    {
    SOMEOBJECTSESSIONID = 0,
    SOMEOBJECTSESSIONIDHASH = hash,
    DEVICEDESC = "some device",
    OPERATINGSYSTEMDESC = "Microsoft Windows NT 6.1.7601 Service Pack 1",
    BROWSERDESC = "Chrome27",
    IPADDRESS = "123.132.123.132",
    SOMEOBJECTSESSIONSTATUSID = 9999999999, 
    CREATEDBYSOMEOBJECTID = 9999999999,
    CREATEDDATE = DateTime.Now,
    UPDATEDBYSOMEOBJECTID = 9999999999,
    UPDATEDDATE = DateTime.Now
    }
);

ctx.SaveChanges()
}

Using this I add a record to the database.. I then went into the database and manually deleted that record..

When I try and run this test again, the call to SaveChanges dies, just sits there.. Now If I do a

 var tmp = ctx.SOMEOBJECTSESSIONs.Count();

I get back a count that is one more than what is in the database.. Which to me suggests EF still has a hook locally to the record I deleted..

I have read numerous articles about refreshing context(didn't work). I have cleared the "Local"

ctx.SOMEOBJECTSESSIONs.Local.Clear()

which also did not work..

I would have thought that the fact I am spawning up a new Entities connection it should be getting the data from the database..

How do I fix this? What am I doing wrong?

Cheers, J

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
John
  • 698
  • 1
  • 11
  • 22
  • 3
    have you press commit in orcle after manully deleted recorde? – Dhaval Patel May 21 '14 at 13:07
  • Thanks @Dhaval, this is what the problem was. Im new to Oracle, more used to Sql Server.. So once committed transaction seemed ok, albeit be nice if EF didnt hang for so long. hope that is configurable.. – John May 21 '14 at 13:17

1 Answers1

0

Create your context as late as possible and dispose it as soon as you are ready.

So preferably dispose it and create a new one; or use Reload, as described in Entity Framework Refresh context?.

Community
  • 1
  • 1
L-Four
  • 13,345
  • 9
  • 65
  • 109