asp.net mvc 4 - C# Complex Property Setter option -


i have asp.net mvc 5 (c#) application , i'm giving users ability posts , comments.

for have model called likes following properties:

public class {     public like()     {         this.createdutc = system.datetime.utcnow;         this.isactive = true;     }     public long id { get; set; }     public string userid { get; set; }     public bool isactive { get; set; }     public liketype type { get; set; }     public datetime createdutc { get; set; }   } 

type enum , can either comments or posts. i've added following navigation property both post model , comment model:

public virtual icollection<like> likes { get; set; } 

my question is, can have setter function in above line of code automatically set comments , posts type? know can use value variable in setter using google couldn't find how use complex types have above (like).

i'm sure better way of doing in repository manually set enum every-time i'm going save like.

update:

seeing how we're starting nice little conversation questions, throw alternative in mix.

how 2 tables base class of like, 1 commentlikes , other postlikes seeing size of table grow fast, i'm thinking separating them possibly thing, right?

i'd rather drop "liketype" , either have comment , post entity in entity , distinguish 1 of them being null or introduce 2 new entities

public class commentlike {     public comment comment { get; set; }     public like { get; set; } } 

which holds comment , , postlike holds post , like. comment looks this

public comment {     public virtual icollection<commentlike> { get; set; } } 

another alternative create separate tables comment , post likes. while ask doable recommend more verbose simpler solution result in code easier maintain , has less bugs. there specific reason want have liketype property?


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -