linq to sql update not working for one column

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
 
A

Alberto Poblacion

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.
 
C

Christoph Basedau

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top