C#C
C#4y ago
İrşat

EF sets a property out of nowhere [Solved] [Answered]

public int RepliesLength { get; set; } = 0;
public int RepliesCount { get; set; } = 0;

public CommentDtoRead_2(ICollection<VoteDto>? Votes, ICollection<ReplyDtoRead_1>? Replies)
{
    if(Replies != null && Replies.Count > 0) {
        this.RepliesLength = Replies.Count(r => r.DeletedStatus!.Body == "Default");
        this.RepliesCount = Replies.Count(r => r.DeletedStatus!.Body == "Default");
    }
}

I have a model with this constructor. Basically, I get the amount of replies which are not deleted through Count. Total is 5 and 3 of them are not deleted.

Literally the same codes. But at the end, RepliesCount returns 5 and RepliesLength returns 3. RepliesLength can have any name. But when I use the name "RepliesCount", it fetches all the replies.

I used breakpoints to see where it comes from since I didn't reference to it anywhere. It starts filling properties, assigns 3 to both, as one would expect. But after filling others properties, for some reason it jumps to setter and assigns 5 to RepliesCount.

My theory; EF can fill the Replies if I want. Perhaps if I write the "Replies" then add "Count" at the end, it automatically runs the Count function and assigns to it? Because I didn't reference it anywhere.
Was this page helpful?