Is it possible that two different classes have a property -a collection of classes and each object knows which of the first two classes it belongs to?

I have next 3 classes

class Review
{
   public int Id{get; set;}
   public string Text{get; set;}
   public ICollection<Comment> Comments{get; set;}
//some additional properties
}
class User
{
   public int Id{get; set;}
   public string Name{get; set;}
   public string Login{get; set;}
   public ICollection<Comment> Comments{get; set;}
//some additional properties
}
class Comment
{
   public int Id{get; set}
   public string Comment{get; set;}
   public ??? Target{get; set;}
}

In this context, a Target is what the comment was attached to. And for some things, I need to know exactly who the target is - a specific user or a specific review. And inheriting from the interface is not suitable due to the strong distinction in the parameters. And i need to use database so object type not for that kind of situation(as i know).



Read more here: https://stackoverflow.com/questions/65724058/is-it-possible-that-two-different-classes-have-a-property-a-collection-of-class

Content Attribution

This content was originally published by RdEErAqUa at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: