Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6203661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:57:15+00:00 2026-05-24T04:57:15+00:00

I have a model as below: public class Post { public int Id {get;set;}

  • 0

I have a model as below:

public class Post
{
    public int Id {get;set;}
    public virtual ICollection<Comment> Comments {get;set;} 
    public virtual ICollection<Reader> Readers {get;set;}
    public int Value {get;set;}
}

The rule is Value = Comments.Count * 2 + Readers.Count.

What is the right and convenient way to deal with the “computed” property of “Value”?

I think it is the best that the “Value” can be calculated and saved automatically when Comments or Readers add/remove element.

but the “DatabaseGeneratedAttribute” seems no use here.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:57:17+00:00Added an answer on May 24, 2026 at 4:57 am

    This is not supported. There is no way to make Value available for linq-to-entities queries if it is not mapped to database column. In case of EF using EDMX for mapping this can be sometimes solved by using custom mapped SQL function or model defined function but code first mapping doesn’t support anything of that. Other way is to create database view and map your entity to view but in such case entity will be read only.

    Once you use .NET code for defining value it is always only client side property computed from data loaded from database. If you don’t want to recompute property every time you need observable collections with event handler changing precomputed value each time the collection changes.

    DatabaseGenerated attribute just marks your property as generated by database – in such case you cannot change its value and database must ensure that correct value will be stored in your table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model public class QuestionViewModel { public string Text { get; set; }
Lets say I have model inheritance set up in the way defined below. class
I have a view model (below). public class TopicsViewModel { public Topic Topic {
Suppose I have the view models below. public class CustomerListViewModel { public IEnumerable<CustomerViewModel> Customers
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,
I have model public class UploadOptionModel { public UploadOptionModel() { OutputFormat = outputFormatList.Select(i =>
I have a ViewModel. something like this public class ViewModel { public int Id
So I have a model below that represents the situation: Students participate in Contests.
I have my entities as below. My data model enforces below and I cannot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.