c# - Model relationships about implementing vote system -


i confused voting system implementation. want know vote , vote down counts of post , save voters voted or down. use below model it.

public class post : entity {     public string title { get; set; }     public virtual user owner { get; set; }     public virtual list<user> upvoters { get; set; }     public virtual list<user> downvoters { get; set; } } 

i feel bit of problem in design because if have represent vote , vote down count of post think have process 2 query.using navigation properties counts cause performance problems if need counts. right?

second aproach below confuse me because voteupcount , votedowncount should handled manualy developer. , reupdate values when voter changed vote , looks bit of code smell.

public class post : entity {     public string title { get; set; }     public virtual user owner { get; set; }     public int voteupcount { get; set; }     public int votedowncount { get; set; }     public virtual list<user> upvoters { get; set; }     public virtual list<user> downvoters { get; set; } } 

can suggest me better ? , why better ? have alternatives ?

lastyly post hold 3 user navigation properties , makes me feel can wrong. there wrong in relationship ??

instinctively, create vote entity, since want save information on votes :

public class vote : entity {     public user user {get;set;}     public int votedirection {get;set;} // 1 or -1     // other info... } 

then add vote field in post class :

public class post : entity {     public string title { get; set; }     public virtual user owner { get; set; }     public virtual list<vote> votes { get; set; } } 

then count sum of votedirection each votes...


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -