© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
57 replies
İ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");
    }
}
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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

solved [Answered]
C#CC# / help
4y ago
Decreasing a property accessibility [Answered]
C#CC# / help
4y ago
❔ DateTime Property [Answered]
C#CC# / help
4y ago