EFDAL: When Is a Primary Key Property Setter Called?

Dec 22, 2010 at 6:54 PM

I'm running into an oddball situation in a WPF app using EFDAL. I'm not sure if it's a WPF issue or an EFDAL issue.

I bind an ObjectSet to a DataGrid, and use it as the source for control values in various columns of the grid. One of those columns is a UserControl which binds to a foreign key field in the Entity. That foreign key field can be null. Another column (for comparison) is a DataGridTextBoxColumn, bound to a string property in the Entity.

If I make a change to the textbox in the DataGridTextBoxColumn I can call SaveChanges() on the EntityContext and all is well.

But if I make a change to the UserControl in the DataGridTemplateColumn, something calls the property setter on the Entity's primary key field (an integer)...which is not good :). Needless to say, that attempts throws an exception because the primary key field is not allowed to be modified, and shouldn't be modified, after it's initially set.

I'm confused as to why changing a string property in the Entity doesn't cause a problem while changing a foreign key property in the Entity does. Why would one situation mark the primary key as "dirty" while the other doesn't?

Am I interacting with that foreign key field incorrectly? I'm assigning it a value directly -- should I be changing the foreign record that it points to in a different way?

- Mark

Coordinator
Dec 30, 2010 at 11:06 PM

Would you please send an example of this failing to chrisd@nhydrate.org? If you could set everything up, I can determine what if anything needs to be fixed. If I get this soon I might be able to get it into the next version.