I have the bellow entities:
public class Notification
{
public int Id { get; set; }
public string Title { get; set; }
public Guid RefId { get; set; }
public Object Ref { get; set; } // << The navigation property: Sometime its type is Poll and sometime is Test, maybe I add other types too
public NotifTypes Type { get; set; }
}
public enum NotifTypes
{
Poll=1,
Test=2,
// Other NotifTypes here
}
//-------------------------------------------------------------------
public class Test
{
public int Id { get; set; }
public string Title { get; set; }
public IEnumerable<Notification> { get; set; }
}
public class Poll
{
public int Id { get; set; }
public string Answer1 { get; set; }
public string Answer2 { get; set; }
public IEnumerable<Notification> { get; set; }
}
OK,
- When the
Typeproperty ofNotificationobject is equalPoll, theRefIdwill fill by aPollId - When type is equal
Test, therefIdwill fill by aTestId.
Now I want conditionally include the related Poll or Test in Ref property. How should I implement it?
I want prevent to add separate Ids like
PollId,TestIdand.... toNotificationbecause I'm sure that each time just one of them has value, so I want have oneRefIdand oneRefproperty instead of them.