Templates A and B both inherit from Templates C.

I have an item that can have either an A or a B as parent.

How can I use the [SitecoreParent] attribute in order to retrieve either according to the circumstances? I tried with

public C Item { get; set; }

but it's always null.

  • 3
    Have you tried with virtual modifier? public virtual C Parent { get; set; }? – Marek Musielak Apr 18 '19 at 13:25

You will need to tell it specifically to infer the type of the parent (also, the property should be marked virtual):

[SitecoreParent(InferType = true)]
public virtual C Parent { get; set; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.