I have a EF model class Comment
with a navigation property ScoreVotes
referencing ScoreVote
which has member int Score
. In Comment
I have the following method Score()
:
public int Score()
{
var votes = this.ScoreVotes;
if (votes == null)
return 0;
else
{
int score = 0;
foreach (var scoreVote in votes)
{
score += scoreVote.Score;
}
return score;
}
}
I have the following questions:
- How can I tell EF to bring over the
Comment
'sScoreVotes
up-front if I know that I will need to calculate the score? (Should I useInclude
?) - If I made
Score
a property whose getter method matched the current method, wouldScore
be recorded in the database? Would it always reflect the last calculated score?