When I try to insert or update data in my WPF usercontrol
datagrid, the data is not being saved to the corresponding property. This is being caused by (at least so I believe) my bound property having the [NotMapped]
attribute, all the other properties without the annotation are working correctly.
The data which need's to be updated is inside a DataGrid
component which is bound to an ObservableCollection
with the appropriate model. Inside the model there are several properties with the [NotMapped]
annotation, these properties should be excluded in the creation of the table (model) in my database, though I do need them for binding input, hence the use of the [NotMapped]
annotation.
Since the data is bound to a ObservableCollection
I can't add the [NotMapped]
properties to the usercontrol
directly (so they wont be a part of the model).
Below an example:
Part of the XAML
In the image below we can see 1 property (pBreedte
) which is 1 of the NotMapped
properties, as well as the itemsource
of the datagrid
:
UserControl Code behind (part of it)
Part of the model which is used in the ObservableCollection
The model is being used for EF6
(code first).
Is there any way that the NotMapped
property values can be stored / saved?
The easiest would be to just include the NotMapped
properties in the database (so removing the annotation completely) but I am trying to avoid this.
More background information
The NotMapped
values are added because they function as a placeholder property. Initially I had several decimal
properties bound to the datagrid
directly, but textboxes can't handle decimal values very well (WPF validation rule preventing decimal entry in textbox?). So I created a string placeholder for those decimal properties, when the form is being saved the decimal properties are being set to their string placeholder counterparts. This way the user can add decimal places without having to use a delay
, value converter
or anything.