开发者

LINQ-to-SQL Update not working correctly

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 p开发者_运维百科roperties 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 :-)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜