I'm having an issue where Entity Framework isn't persisting changes to the DB. I use a static method to load up some values and the Entity context is thrown away (in a using statement).
The objects are then loaded into a WPF DataGrid where they can be manipulated by the end user.
When the user is finished making changes an "update" button is pressed and the list of objects is sent back to the data layer to be persisted to the DB. I can see objects that were changed in the UI reflect their new value (ie not a data binding issue).
I would assume since the entity context that loaded the objects has since been disposed of I should then attach these objects to be persisted to the newly created context. Correct? When I do this the entity state of the modified object (I can see that is what the state is set to) changes to "Unchanged". Nothing is persisted to the DB.
What the heck am I missing?!
Here is the code to load and update the values:
public static List<SSIS_Configuration> GetConfigurationValuesForTenant(string tenantKey, SqlConnectionString connectionString)
{
List<SSIS_Configuration> configStrings = new List<SSIS_Configuration>();
if (connectionString.IsValid())
{
try
{
using (SSISFrameworkEntities entities = new SSISFrameworkEntities(connectionString.ToEDMXString("SSISFramework.SSISFramework")))
{
string configFilterStartingValue = "CommonConfig_" + tenantKey;
configStrings = (from configString in entities.SSIS_Configurations
where configString.ConfigurationFilter.StartsWith(configFilterStartingValue)
select configString).ToList();
}
}
catch { }
}
return configStrings;
}
public static void UpdateConfigurations(List<SSIS_Configuration> configurations, SqlConnectionString connectionString)
{
if (connectionString.IsValid())
{
try
{
using (SSISFrameworkEntities entities = new SSISFrameworkEntities(connectionString.ToEDMXString("SSISFramework.SSISFramework")))
{
foreach (SSIS_Configuration config in configurations)
{
entities.Attach(config);
}
entities.SaveChanges();
}
}
catch { }
}
}