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

  • SEARCH
  • Home
  • 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 7775237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:34:46+00:00 2026-06-01T17:34:46+00:00

I have a custom base type called MyEntityBase for the superclass of the types

  • 0

I have a custom base type called MyEntityBase for the superclass of the types in my auto-generated DataContext class, MyContext. In attempting to create a mock data context, I decided to implement INotifyPropertyChanged on MyEntityBase so I can generically track changes.

Here’s what my class looks like:

public abstract class MyEntityBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
}

Based on this class, I have created a generic Repository<T> class for storing instances of a specific type of entity. The basic idea behind this class is to provide methods similar to a datacontext, but instead backed by an in-memory list. I also want to simulate tracking changes, since the change set is important to the business logic of our application for syncing with 3rd-party systems.

Here is a basic shell implementation of Repository<T>:

public class Repository<T>
    where T : MyEntityBase, INotifyPropertyChanged
{
    protected List<T> _data;
    public Repository(List<T> data)
    {
        this._data = data;
        foreach (var entity in this._data)
        {
            entity.PropertyChanged += new PropertyChangedEventHandler(entity_PropertyChanged);
        }
    }

    protected void entity_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        Console.WriteLine("HERE");
    }
}

Now I create a simple repository of type Employee, populate some data, and attempt to modify properties of the data. I would expect that the PropertyChanged event is raised since the Employee object has property-change notification built-in from the auto-generated DataContext. However, when I run the following code, I do not see HERE generated in the output anywhere:

var data = new List<Employee> {
    new Employee { FirstName = "Bob" },
    new Employee { FirstName = "Joe" },
};

var repo = new Repository<Employee>(data);

// This should fire the PropertyChanged event
data[0].FirstName = "John";

What am I doing wrong?


Update: If I change the line that subscribes to the event to the following:

(entity as Employee).PropertyChanged += ...

Then it works fine. However, T is already known to be Employee and entity is an instance of type Employee, so what’s the difference? Even if I make the event in MyEntityBase to be virtual, it still doesn’t work properly.

  • 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-01T17:34:47+00:00Added an answer on June 1, 2026 at 5:34 pm

    I have a workable solution implemented, so I will answer my own question. Since I already have a command-line tool FindAndReplaceText.exe that I use to do some customizations to the auto-generated MyDataContext.dbml file, I just added another call at the end where I modify all events in the generated MyDataContext class to include override. Coupled with making my base class use virtual in the definitions of the events, this solves the problem:

    FindAndReplaceText.exe -c ^
        MyDataContext.cs ^
        "public event" ^
        "public override event"
    

    Now the property changes notify properly in my test code.

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

Sidebar

Related Questions

I have a custom base user control in silverlight. <UserControl x:Class=Problemo.MyBaseControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008
I have a custom class of type NSObject that contains a single NSMutableArray. This
I have a custom c# type like (just an example): public class MyVector {
I currently have a Content Type called News which is very simple (No custom
I have custom class that extends WebViewPage that I use as the base for
I have a standard ActiveRecord model with the following: class MyModel < ActiveRecord::Base custom_method
I have a public static property in a class. The class has some custom
I have created custom exception class public class Web2PDFException : Exception { public Web2PDFException(string
I have a custom exception class which contains some additional fields. I want these
I have the following cell which is used for my custom column data type

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.