Object Reference Not Set to an Instance of an Object
Posted: Thu 28 Apr 2011 14:06
When calling the SaveChanges() method of the entity context I am getting an "Object reference not set to an instance of an object" error. I am using self-tracking entities, dotConnect for Oracle ver 6.10 Professional Trial and VS 2010.
This is the stack trace:
And this is an example of the code causing the problem:
The Person object is inherited from LegalEntity in the entity model. The above code is in a procedure which is called by another method which updates data in its own using block and then, outside the using block, it calls this method passing in the EntityId value. I verified that a Person object is being returned by the query and when the ReferredTo value is changed, the change tracking class is showing the object as modified and has the original and new values. I also tried running the code in LINQPad and got the same results.
Thanks!
This is the stack trace:
Code: Select all
Devart.Common.Entity.au.a(cq A_0, EntitySetBase A_1)
Devart.Common.Entity.au.b(bp A_0, StringBuilder A_1, a3 A_2)
Devart.Common.Entity.au.a(bp A_0, DbCommand A_1)
Devart.Common.Entity.co.a(bp A_0, DbCommandBase A_1)
Devart.Common.Entity.co.c()
Devart.Data.Oracle.Entity.OracleEntityProviderServices.a(DbProviderManifest A_0, DbCommandTree A_1)
Devart.Data.Oracle.Entity.OracleEntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
System.Data.Objects.ObjectContext.SaveChanges()
EntityModuleBL.EntityManager.SetDependentRecordsToInactive(LegalEntity value)
EntityModuleBL.EntityManager.UpdateEntity(LegalEntity value, IIdentity identity)
EntityModuleTests.EntityModelBLTests.EntityManagerTests.CanDeleteAnEntity()
Code: Select all
using (EntitiesContext context = new EntitiesContext())
{
entity = (from le in context.LegalEntities.OfType()
where le.EntityId == entityId
select le).FirstOrDefault();
entity.StartTracking();
entity.ReferredTo = "Test";
context.LegalEntities.ApplyChanges(entity);
context.SaveChanges();
}
Thanks!