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 8112119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:22:12+00:00 2026-06-06T02:22:12+00:00

I am Using C# 2010 Entity framework code first If I have A class

  • 0

I am Using C# 2010 Entity framework code first
If I have A class like this

partial class test    
{
        public double value1;
        public double value2;
        public double value3;
        public double totals;
}

That generated by code

how could I create partial class to calc totals

partial class test    
{
        public double totals { get  { return value1 + value2 + value3; }    }

1 – you know it is not practical to change the generated class.
2 – there is no way to partially define the property totals.
3 – And using metadata class does not update totals till savechanges.

I’ll appreciate If anyone could define how can I implement OnpropertyChanged and used to solve this problem

Thanks

  • 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-06-06T02:22:15+00:00Added an answer on June 6, 2026 at 2:22 am

    Your property in the second class is missing the “get” keyword:

    partial class test    
    {
            public double totals {  
                get { return value1 + value2 + value3; }
            }
    }
    

    Alternatively you could define a Total() method.

    As far as I can tell from your question (“how could I create partial class to calc totals”), you don’t need to use OnPropertyChanged because the totals property/method will run the calculation each time with the new values in totals. You can remove that field from the original class as it’s a calculation and really shouldn’t be stored.

    If you must actually update a total value in the database you can use the OnPropertyChanged partial methods as you suggested. You’ll need to use properties to call the new method:

    partial class test
    {
        public double Value1
        {
            get { return value1; }
            set
            {
                value1 = value;
                Onvalue1Changed(value);
            }
        }
    
        partial void Onvalue1Changed(double value)
        {
            UpdateTotals();
        }
    
        private void UpdateTotals()
        {
            totals = value1 + value2 + value3;
        }
    }
    

    You should make the original fields private and only provide public access through the property. This is not only better code design but also allows you to implement the kind of functionality you desire.

    There are, of course, other patterns that you can follow, but this should get you started.

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

Sidebar

Related Questions

I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First
I'm wondering if using VS.Net 2010, I can have Entity Framework 3.5 code running
My scenario I'm using Visual Studio 2010 with Entity Framework 4.1 I have a
I've created a web application project in Visual Studio 2010 using Entity Framework Code
In the following blog: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx The blog contains the following code sample: public class
I am using C#, Visual Studio 2010 and Entity Framework 4. I have an
I'm using Visual Studio 2010 RTM with .NET/Entity Framework 4 RTM with a model
I am using Entity framework with following tools: MS Visual studio 2010 Professional SP1
I am using Entity Framework, C# 4.0 and Visual Studio 2010. I need to
I am getting started with Entity Framework using EF4 in VS 2010 RC. So

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.