locked
ChangeInterceptor causes problem on Save RRS feed

  • Question

  • Hi,
    I have implemented ChangeInterceptors in my ADO.NET Data Service and I have a problem with saving changes.
    So, when I create one object and add link to it everything works ok, but when I create two or more object and add links to them exception occurs.When I remove interceptors everything works ok, so it seems like interceptors caused this problem.
    Interceptors have simple logic which changes properties which are not navigation properties.

    Exception message: 

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
      <code></code>
      <message xml:lang="en-US">An error occurred while processing this request.</message>
      <innererror xmlns="xmlns">
        <message>The object being attached is in an added or deleted state. Relationships cannot be created for objects in this state.</message>
        <type>System.InvalidOperationException</type>
        <stacktrace>   at System.Data.Objects.DataClasses.RelatedEnd.ValidateEntityForAttach[TEntity](TEntity entity, Int32 index, Boolean allowCollection)&#xD;
       at System.Data.Objects.DataClasses.RelatedEnd.Attach[TEntity](IEnumerable`1 entities, Boolean allowCollection)&#xD;
       at System.Data.Objects.DataClasses.RelatedEnd.System.Data.Objects.DataClasses.IRelatedEnd.Attach(IEntityWithRelationships entity)&#xD;
       at System.Data.Services.Providers.ObjectContextServiceProvider.AddReferenceToCollection(Object targetResource, String propertyName, Object resourceToBeAdded)&#xD;
       at System.Data.Services.Serializers.Deserializer.HandleBindOperation(RequestDescription description, Object linkResource)&#xD;
       at System.Data.Services.Serializers.Deserializer.HandlePostRequest(RequestDescription requestDescription)&#xD;
       at System.Data.Services.DataService`1.HandlePostOperation(RequestDescription description, IDataService dataService)&#xD;
       at System.Data.Services.DataService`1.ProcessIncomingRequest(RequestDescription description, IDataService dataService)&#xD;
       at System.Data.Services.DataService`1.BatchDataService.HandleBatchContent(Stream responseStream)</stacktrace>
      </innererror>
    </error>


    Thursday, October 30, 2008 11:31 AM

All replies

  • Can you please send us exactly what operations you are trying to do and what changes you are making in the ChangeInterceptors?

     

    Thanks

    Pratik

    Thursday, October 30, 2008 5:11 PM
    Moderator
  • Ok, in every interceptor I call the same static method which changes some properties.
    Here is the example which causes exception:

            [ChangeInterceptor("SomeEntity")]
            public void ChangeWord(Word instance, UpdateOperations operation)
            {
                ChangeInstance(instance, operation);
            }

    private static void ChangeInstance<T>(T instance, UpdateOperations operation)
    {

    if (operation == UpdateOperations.Add)

    {

    string currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;


    Type instanceType = instance.GetType();


    PropertyInfo propertyCreator = instanceType.GetProperty("Creator");


    propertyCreator.SetValue(instance, currentUser, null);

    }

    }

    Friday, October 31, 2008 6:50 AM