Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Why Linq-SQL generated code implements INotifyPropertyChanging

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrus - 09 Mar 2008 11:15 GMT
I noticed that sqlmetal generated code in northwind.designer.cs implements
two interfaces:

public partial class Customer : INotifyPropertyChanging,
INotifyPropertyChanged {

public string CustomerID  {
  set   {
...
    this.SendPropertyChanging();
    this._CustomerID = value;
    this.SendPropertyChanged("CustomerID");
...

INotifyPropertyChanged alone allows to track changes well at property level.

Why they implemented also INotifyPropertyChanging ? INotifyPropertyChanging
allows to track changes only at entity level and does not even provide
changed property name.
Looks like junk code.

Andrus.
Frans Bouma [C# MVP] - 09 Mar 2008 11:53 GMT
> I noticed that sqlmetal generated code in northwind.designer.cs
> implements two interfaces:
[quoted text clipped - 17 lines]
> and does not even provide changed property name.  Looks like junk
> code.

    Try binding a list of entities to a grid or control and you'll quickly
learn that INotifyPropertyChanged is required to make them function
properly together with databinding oriented code.

        FB

Signature

------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Andrus - 09 Mar 2008 12:02 GMT
Frans,

> Try binding a list of entities to a grid or control and you'll quickly
> learn that INotifyPropertyChanged is required to make them function
> properly together with databinding oriented code.

Sure.
However my question was about *INotifyPropertyChanging*
but you replied about  *INotifyPropertyChanged*

Andrus.
Peter Morris - 09 Mar 2008 13:31 GMT
I believe that when you do SQL->LINQ you are able to write code in a partial
class and therefore hook into the part where the property is set, so that
you may implement any required logic.

A quick google should provide some examples.

Pete
Andrus - 09 Mar 2008 16:58 GMT
>I believe that when you do SQL->LINQ you are able to write code in a
>partial class and therefore hook into the part where the property is set,
>so that you may implement any required logic.

Pete,

Yes, this is possible.
Any idea why MS generated code contains  INotifyPropertyChanging
implementation ?
It is not needed for any purpose.

Andrus.
Jon Skeet [C# MVP] - 09 Mar 2008 17:16 GMT
> >I believe that when you do SQL->LINQ you are able to write code in a
> >partial class and therefore hook into the part where the property is set,
[quoted text clipped - 4 lines]
> implementation ?
> It is not needed for any purpose.

From
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?
FeedbackID=290470

<quote>
The sole purpose of SendPropertyChanging() was to provide a lightweight
and performant way to detect when an object is changed so that a copy
can be created for keeping original values for use in optimistic
concurrency. Hence, we deliberately did not create event args to ensure
better performance. This is quite different from the traditional
databinding use of INotifyPropertyChanged where the property name is
provided.
</quote>

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Andrus - 09 Mar 2008 21:21 GMT
Jon,

> <quote>
> The sole purpose of SendPropertyChanging() was to provide a lightweight
[quoted text clipped - 5 lines]
> provided.
> </quote>

MS Entity framework seems to generate better code by using

ReportPropertyChanging("SocialSecurityNumber")

sample:

[EdmScalarPropertyAttribute()]
public string SocialSecurityNumber {
get { return _socialSecurityNumber; }

set {
OnSocialSecurityNumberChanging(value);
ReportPropertyChanging("SocialSecurityNumber");
_socialSecurityNumber = value;
ReportPropertyChanged("SocialSecurityNumber");
OnSocialSecurityNumberChanged();
}
}

The ReportPropertyChanging and ReportPropertyChanged methods defer to an
Entity Framework ChangeTracker object that monitors current and original
property values.

So was  Microsoft changed their mind in EF ?
Why they are not consistent, implement it differently for Entity framework
!?

Andrus.
Jon Skeet [C# MVP] - 09 Mar 2008 23:12 GMT
<snip>

> So was  Microsoft changed their mind in EF ?
> Why they are not consistent, implement it differently for Entity framework
> !?

Different teams implemented LINQ to SQL and the EF, as far as I'm
aware.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.