By Gus Cavalcanti

2010-09-16 17:16:21 8 Comments

I have a property auto-generated from database in my edmx: Description. I then create a "partial class" .cs file for the entity and add a read-only property: ShortDescription. ShortDescription's getter simply processes Description (removes line feed, carriage return, etc).

How can I raise property change notification for ShortDescription on the setter of Description?



@Dimestore Cowboy 2011-09-30 19:16:50

The methods are partial also, so in your partial class you can add code like this

 partial void OnDescriptionChanged()

@Randolpho 2010-09-16 17:22:41

This is going to be a hack, but it can be done.

First, you need to override ReportPropertyChanging and ReportPropertyChanged. Then check the parameter for the name of your property... in this case "Description". If it occurs, call ReportPropertyChanging or ReportPropertyChanged with the derived property name, in this case "ShortDescription". For any other value of the parameter, call the base version of ReportPropertyChanging/Changed.

Edit: For example:

    protected override void OnPropertyChanging(string property)
        if (property == "Description")

    protected override void OnPropertyChanged(string property)
        if (property == "Description")

@Randolpho 2010-09-16 17:34:54

Ok, I deserve any downvotes... for some reason MS sealed ReportPropertyChanging/Changed, but left OnPropertyChanging/Changed open. Use the code example, not the prose example.

@Gus Cavalcanti 2010-09-16 17:35:04

Thanks! I forgot to look at non-partial events! :)

Related Questions

Sponsored Content

28 Answered Questions

[SOLVED] Fastest Way of Inserting in Entity Framework

11 Answered Questions

[SOLVED] How can I get Id of inserted entity in Entity framework?

18 Answered Questions

[SOLVED] How do I view the SQL generated by the Entity Framework?

16 Answered Questions

[SOLVED] Entity Framework vs LINQ to SQL

33 Answered Questions

4 Answered Questions

[SOLVED] Creating a non mapped property in an entity (entity framework)

  • 2010-01-01 04:06:27
  • ryudice
  • 35549 View
  • 36 Score
  • 4 Answer
  • Tags:   entity-framework

8 Answered Questions

12 Answered Questions

1 Answered Questions

Sponsored Content