linq to sql update not working for one column

  • Thread starter Thread starter Tom Overton
  • Start date Start date
T

Tom Overton

I am trying to do a very simple update to a table and it works fine
for one column (ins_type column) but not the other column (status
column). Both are char type columns. Here is the code and the
resulting SQL:

var t = db.tblins_infos.Single(i => i.info_id == tertiary_info_id);
t.status = 'A';
t.ins_type = 'P';
db.SubmitChanges();

UPDATE [dbo].[tblins_info]
SET [ins_type] = @p1
WHERE [info_id] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [29475]
-- @p1: Input Char (Size = 1; Prec = 0; Scale = 0) [P]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build:
3.5.30729.1

As you can see it ignored the [status] column update and only updated
the [ins_type] column. If I try to only update the status column
SubmitChanges() doesn't even generate an update statement at all.

Is there something wrong with updating a table that has a column name
of "status"?

-Tom
 
Tom Overton said:
I am trying to do a very simple update to a table and it works fine
for one column (ins_type column) but not the other column (status
column). Both are char type columns. Here is the code and the
resulting SQL:

var t = db.tblins_infos.Single(i => i.info_id == tertiary_info_id);
t.status = 'A';
t.ins_type = 'P';
db.SubmitChanges();

UPDATE [dbo].[tblins_info]
SET [ins_type] = @p1
WHERE [info_id] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [29475]
-- @p1: Input Char (Size = 1; Prec = 0; Scale = 0) [P]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build:
3.5.30729.1

As you can see it ignored the [status] column update and only updated
the [ins_type] column. If I try to only update the status column
SubmitChanges() doesn't even generate an update statement at all.

Is there something wrong with updating a table that has a column name
of "status"?

Does the "status" field already have a value of 'A'? If you are setting
it to the same existing value, then this could be the reason why nothing is
being generated in the Sql statement to change it.
 
Tom said:
I am trying to do a very simple update to a table and it works fine
for one column (ins_type column) but not the other column (status
column). Both are char type columns. Here is the code and the
resulting SQL:

var t = db.tblins_infos.Single(i => i.info_id == tertiary_info_id);
t.status = 'A';
t.ins_type = 'P';
db.SubmitChanges();

UPDATE [dbo].[tblins_info]
SET [ins_type] = @p1
WHERE [info_id] = @p0
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [29475]
-- @p1: Input Char (Size = 1; Prec = 0; Scale = 0) [P]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build:
3.5.30729.1

As you can see it ignored the [status] column update and only updated
the [ins_type] column. If I try to only update the status column
SubmitChanges() doesn't even generate an update statement at all.

Is there something wrong with updating a table that has a column name
of "status"?

According to the generated SQL the type of the parameter @p0,
which refers to the status-column/property should be *int* not *char*,
and your 'A' value is converted to '29475' for some reason.

Is this type-conversion from char to int intended or accidental?
Did you miss to run SqlMetal and remap your LINQ-classes
after a schema-change?

Christoph
 
Back
Top