tags:

views:

32

answers:

1

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 :-)

A: 

Hi James,

First of all check if you are using the UsageID in the where clause to get the appropriate Usage.

Next check if those properties (ResourceID and UsageTypeID) are made as read only in the DBML.

Hope this helps.

Thanks, Raja

Raja
Readonly is set to false, and the other properties are being updated. When you step through the code the properties for ResourceID and TypeID are being set and the relevant designer code being executed.
m0gb0y74
Check out this link: http://www.codeproject.com/Messages/2918828/LINQ-to-SQL-bug-when-updating-foreign-key-fields.aspxHope this helps.
Raja