SaveEntityCollection throws error

Posts   
 
    
winter
User
Posts: 5
Joined: 21-Oct-2008
# Posted on: 21-Oct-2008 20:06:56   

Error: Operation is not valid due to the current state of the object.

The Code:

    private ServiceOperationResult<EntityCollection<SurveyAnswerEntity>> UpdateSurveyAnswerRecords(EntityCollection<SurveyAnswerEntity> p_entities, bool p_isImported)
    {
        try
        {
            ServiceOperationResult<EntityCollection<SurveyAnswerEntity>> returnValue;

            foreach (SurveyAnswerEntity entity in p_entities)
            {
                entity.IsImportedCsv = p_isImported;
                entity.ImportDate = DateTime.Today;
            }

            returnValue = _persistence.SaveEntityCollection(p_entities);

            return returnValue;
        }

        catch (Exception ex)
        {
            if (_logger.IsErrorEnabled)
            { _logger.Error("Unexpected error in: UpdateSurveyAnswerRecord", ex); }

            return new ServiceOperationResult<EntityCollection<SurveyAnswerEntity>>(ServiceOperationResultType.OperationCallFailed, ex.Message + "\r\n" + "Method: UpdateSurveyAnswerRecord", null);
        }
    }

I've even tried manually setting IsDirty to true but that doesn't work either.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Oct-2008 21:22:34   

Please can you supply us with some more information to allow us to investigate further.

See the guidlines here... http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9076

winter
User
Posts: 5
Joined: 21-Oct-2008
# Posted on: 21-Oct-2008 21:50:29   

Sorry about that. Here is the information I think you're looking for.

**LLBLGEN Pro Version + Builder **v2.5

Library Version 2.5.0.0

Template grp: Adapter

**.NET Version: **2008 (3.5)

Database: SQL Server 2005

Stacktrace: at System.Reflection.RuntimeMethodInfo.GetGenericMethodDefinition() at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.MethodsEquals(MethodInfo method, ProxyMethodExpectationTriplet triplet) at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.GetAllExpectationsForProxyAndMethod(Object proxy, MethodInfo method) at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.CalcExpectedAndActual.Calculate(Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.CalcExpectedAndActual..ctor(UnorderedMethodRecorder parent, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.UnexpectedMethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.DoGetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.MethodRecorders.MethodRecorderBase.GetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.ReplayMockState.DoMethodCall(IInvocation invocation, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args) at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at IPersistenceServiceProxy2629e3db18c34b9b8c35dccefb6eb34c.SaveEntityCollection[T](T p_EntityCollection) at Org.HealthNow.HRA.ContractImplementation.CareAdvanceIntegrationService.BuildUDAFeedFile() in D:\Apps\HRA\31593\Trunk\HealthRiskAssessment\Contract Implementations\ContractImplementation\CareAdvanceIntegrationService.cs:line 110

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Oct-2008 22:02:12   

Thanks

So the exception is occuring on the call to SaveEntityCollection ? Could you also supply the exception details ?

Are any of the LLBLGen objects being Mocked ?

Thanks

Matt

winter
User
Posts: 5
Joined: 21-Oct-2008
# Posted on: 22-Oct-2008 14:31:03   

Error: Operation is not valid due to the current state of the object.

I am mocking the _persistence object.

When I build the collection that I'm modifying and trying to save, I sort it. So the entities are not in the same order as they are in the database.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 22-Oct-2008 16:05:16   

Library Version 2.5.0.0

That's not a valid runtime library version, please go back to the guidelines thread, to know how to get the RTL version.

I am mocking the _persistence object.

Is this a DataAccessAdapter object?

winter
User
Posts: 5
Joined: 21-Oct-2008
# Posted on: 22-Oct-2008 17:36:14   

Walaa wrote:

Library Version 2.5.0.0

That's not a valid runtime library version, please go back to the guidelines thread, to know how to get the RTL version.

I am mocking the _persistence object.

Is this a DataAccessAdapter object?

Sorry...the version is 2.5.8.604

_persistence isn't a DataAccessAdapter object, but we do utilize the DataAccessAdapter

Here is the code from _persistence:

    public ServiceOperationResult<T> SaveEntityCollection<T>(T p_EntityCollection) where T : IEntityCollection2
    {
        try
        {
            using (IDataAccessAdapter daa = GetDataAccessAdapter())
            {
                daa.SaveEntityCollection(p_EntityCollection);

                return new ServiceOperationResult<T>(ServiceOperationResultType.OperationCallSuccessful, p_EntityCollection);
            }
        }

        catch (Exception ex)
        {
            return new ServiceOperationResult<T>(ServiceOperationResultType.OperationCallFailed, ex.Message, p_EntityCollection);
        }
    }
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 23-Oct-2008 12:07:18   

On which line of code has the exception been thrown?

winter
User
Posts: 5
Joined: 21-Oct-2008
# Posted on: 23-Oct-2008 16:19:39   

returnValue = _persistence.SaveEntityCollection(p_entities);

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 23-Oct-2008 21:14:21   

We still need to see the exception details - it appears from the stack trace you posted earlier that the error does not appear to be coming from LLBLGen.

Do you get the same error if you replace the mocked _persistence object with an actual one that does the same...?

Thanks