Ive created a small method which either saves or deletes a relation but when ever the .delete method is hit its not removed from the database. It worked fine for saving it but will not remove it.
The method looks like this :
var relationService = ApplicationContext.Current.Services.RelationService;
IPublishedContent currentmember = Members.GetCurrentMember();
var areRelated = relationService.AreRelated(currentmember.Id, ProjectId, "memberFollow");
var relType = relationService.GetRelationTypeByAlias("memberFollow");
IRelation r = new Relation(currentmember.Id, ProjectId, relType);
if (!areRelated)
{
relationService.Save(r);
}
else
{
relationService.Delete(r);
}
And the delete is hit but nothing happens. My relation looks like this :
I believe the problem is that you are deleting a "new" relation and not an existing relation.
With IRelation r = new Relation(currentmember.Id, ProjectId, relType); you are creating a new Relation that does not have an identity (id) yet. It won't have an identity until its saved or loaded from the service/database. You will have to call relationService.Delete(r); with a relation that actually has an identity.
Isnt there like a method for it ? Cannot seem to find it, right now im doing like above but dunno if its like a performence blocker(dont know much about the underlying part of C# and Lambda).
Relation not being deleted
Hey there
Ive created a small method which either saves or deletes a relation but when ever the .delete method is hit its not removed from the database. It worked fine for saving it but will not remove it.
The method looks like this :
And the delete is hit but nothing happens. My relation looks like this :
I believe the problem is that you are deleting a "new" relation and not an existing relation.
With
IRelation r = new Relation(currentmember.Id, ProjectId, relType);
you are creating a new Relation that does not have an identity (id) yet. It won't have an identity until its saved or loaded from the service/database. You will have to callrelationService.Delete(r);
with a relation that actually has an identity.Hope this helps,
Morten Christensen
ARH of course makes sense !
Ill get back to you if it works thx so far !
It works like a charm Morten thx..
A quick one if you know it (and ofcourse you do since your da champo).
Isnt there like a method for it ? Cannot seem to find it, right now im doing like above but dunno if its like a performence blocker(dont know much about the underlying part of C# and Lambda).
is working on a reply...