Search code examples
c#genericsneo4jclient

The type arguments for method cannot be inferred from the usage error for creating a relationship


So I have a class that describes the Relationship like so:

public class GraphRelationship<TObject> : Relationship<RelationshipObject>, IRelationshipAllowingSourceNode<TObject>, IRelationshipAllowingTargetNode<TObject>
    {
        string RelationshipName;

        public GraphRelationship(string RelationshipName, NodeReference targetNode, RelationshipObject relationshipTypeObject)
            : base(targetNode, relationshipTypeObject)
        {
            this.RelationshipName = RelationshipName;
        }

        public override string RelationshipTypeKey
        {
            get { return RelationshipName; }
        }
    }

Now I have a method that I want to use to create an instance of the above mentioned class, but I get this The type arguments for method cannot be inferred from the usage error.

Here is the method:

public RelationshipReference CreateObjectRelationship(string relationshipType, string parentObjectId, string childObjectId, RelationshipObject relationshipProperties)
{
    RelationshipReference relationshipReference = 0;

    NodeReference parentNodeReference = GetObjectReference(parentObjectId);
    NodeReference childNodeReference = GetObjectReference(childObjectId);

    //This is where the error is
    relationshipReference = GraphConnection.CreateRelationship(parentNodeReference, new GraphRelationship<RelationshipObject>(relationshipType, childNodeReference, relationshipProperties));

    return relationshipReference;
}

enter image description here

Im sure this is a trivial problem, but how would i fix this?


Solution

  • So I fixed it, my NodeReferences needed to be of Type <TObject>

    NodeReference<TObject> parentObjectReference = GetObjectReference(Id);