Using MVVM and EF...I have a datagrid binding to a View Model (using ObservableCollection). The view model has a save command which simply calls the SaveChanges command of the Data Context. However, when a user adds a new row to the datagrid, the new entity is detached. Is there any easy way to automatically attach it when it gets created. Currently, I'm having to do this in the Save command of my View Model and it seems a bit clunky:
foreach (var dataItem in _DataList) // where _DataList is the ObservableCollection
{
if (dataItem.EntityState == EntityState.Detached)
{
_DataContext.AddToTestTables(dataItem);
}
}
_DataContext.SaveChanges();