This project is read-only.

EFDAL: When Is a Primary Key Property Setter Called?

Dec 22, 2010 at 7: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

Dec 31, 2010 at 12:06 AM

Would you please send an example of this failing to 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.