You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
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;
}
The text was updated successfully, but these errors were encountered:
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;
}
(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;
}
The text was updated successfully, but these errors were encountered: