I have the following simple data model:
Resource
{
ResourceId
ResourceName
}
UsageType
{
UsageTypeId
UsageTypeName
}
Usage
{
UsageId
UsageTypeId
ResourceTypeId
Percentage
}
When I change the UsageTypeId
, ResourceTypeId
and Percentage
values on a Usage
object and then issue SubmitChanges()
LINQ-to-SQL only issues a SQL statement to change the Percentage
value (monitored via SQL Profiler).
If I step through the code I see the properties being set for UsageTypeId
and ResourceTypeId
with the correct values, but they never make it to the database. The properties hold the correct values right up until SubmitChanges()
is called.
I am making changes as follows:
Usage usage = {get the Usage object from the datacontext};
usage.ResourceId = newValue1;
usage.UsageTypeId = newValue2;
usage.Percentage = newValue3;
What is really annoying is that if I call the method from a test fixture it works correctly and updates the database, but when called from anywhere else only the none foreign key columns are updated.
James :-)