Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoveReferenceFromCollection not implemented! And better support for the 'propertyName' argument! #6

Open
legacy-carlostorrao opened this issue Jun 25, 2013 · 0 comments

Comments

@legacy-carlostorrao
Copy link

Hi again. I notice that following limitations / issues in the current version of the Toolkit:

(1) AddReferenceToCollection do not store anywhere the 'propertyName' argument, and for my use-case this argument is mandatory, or else, I cannot know exactly in which sub-property exactly of an entity should be added the new entity. E.g. POST http://server/OData.svc/Users('foo')/$links/Products
If the Users entity have the same Type for /Products and for /SpecialProducts is impossible to know where to add the new entity in which collection.
My change was the following:

public void AddReferenceToCollection(object targetResource, string propertyName, object resourceToBeAdded)
{
this._currentOperation = "AddReferenceToCollection";
this._currentOperationProperty = propertyName;
this._currentEntity = targetResource;
this._currentRelatedEntity = resourceToBeAdded;
}

    [...]

    public void SaveChanges()
    {
        if (_currentOperation == null)
            return;

        var repository = RepositoryFor(_currentEntity.GetType().FullName);

        if (repository == null)
            return;

        if (_currentOperation == "CreateResource" || _currentOperation == "ModifyResource")
            ExecuteMethodIfExists(repository, "Save", _currentEntity);

        if (_currentOperation == "DeleteResource")
            ExecuteMethodIfExists(repository, "Remove", _currentEntity);

        if (_currentOperation == "AddReferenceToCollection")
            ExecuteMethodIfExists(repository, string.Format("Create{0}Relation", _currentOperationProperty), _currentEntity, _currentRelatedEntity);

        if (_currentOperation == "RemoveReferenceFromCollection")
            ExecuteMethodIfExists(repository, string.Format("Remove{0}Relation", _currentOperationProperty), _currentEntity, _currentRelatedEntity);
    }

(2) RemoveReferenceFromCollection is not implemented. This do not work for the following example:

DELETE http://server/OData.svc/Users('foo')/$links/Products('xpto')

I adapted the Add implementation to this Remove method, and this was the result:

public void RemoveReferenceFromCollection(object targetResource, string propertyName, object resourceToBeRemoved)
{
this._currentOperation = "RemoveReferenceFromCollection";
this._currentOperationProperty = propertyName;
this._currentEntity = targetResource;
this._currentRelatedEntity = resourceToBeRemoved;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant