cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Update entity with string as PK in EntityFramework and SQL Anywhere as provider

Former Member
4,516

I have simple table in Sybase

-- Creating table 'SimpleText'
CREATE TABLE [dbo].[SimpleText] (
    [Id] nvarchar(10)  NOT NULL,
    [SimpleValue] nvarchar(120)  NULL
);
GO
-- Creating primary key on [Id] in table 'SimpleText'
ALTER TABLE [dbo].[SimpleText]
ADD CONSTRAINT [PK_SimpleText]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

Based on this table it is created an model in entity framework (using 4.3). Insert and delete is not a problem.

However when updating the table it generates an error when primary key is '[char][number]' i.e. a1 where it says that column a1 it not found. By using a simple trace tool this is the sql generated :

update [dbo].[SimpleText]
set [SimpleValue] = :p0
where ([Id] = :p1)
 and (Id = a1)
p0 = simpleTextValueUpdateda1
p1 = a1

Update code is as follow in C#:

  using (var model = new Entities())
  {
    var entString = model.SimpleText.Select(t => t);
    foreach (var simpleText in entString)
    {
      simpleText.SimpleValue = "simpleTextValueUpdated" + simpleText.Id;
    }
    model.SaveChanges();
  }

There's not an issue if the same key is only a number. Using SqlAnywhere12, Microsoft EF4.3, C# on .NET 4

Has anyone experienced the same? Is there a fix to ensure that text is apostrophed correctly in the sql?

Update:

Running the same project on another computer, everything works fine. The code is identical. So tracing the update it shows a quite important difference. Why is the additional and added to the update query?

Computer A - works like a charm (trace output)

update [dba].[SimpleText]
set [SimpleValue] = :p0
where ([Id] = :p1)

p0 = simpleTextValueUpdateda-1
p1 = a-1

Computer B - additional and generated for the update statement (trace output).

update [dba].[SimpleText]
set [SimpleValue] = :p0
where ([Id] = :p1)
 and (Id = a-1)
p0 = simpleTextValueUpdateda-1
p1 = a-1

Computer A: SQL Anywhere 12.01.3152 Computer B: SQL Anywhere 12.01.3726

I don't think the difference in SQL Anywhere is causing this, but somehow the generated SQL is different.

UPDATE

Update to EBF 3726 on Computer A is causing an exception on .SaveChanges().

  InnerException: iAnywhere.Data.SQLAnywhere.SAException
       Message=Column 'a' not found
       Source=SQL Anywhere .NET Data Provider
       ErrorCode=-2147467259
       NativeError=-143
       StackTrace:
            at iAnywhere.Data.SQLAnywhere.SACommand.ExecuteNonQuery()
            at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
            at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
       InnerException:

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

This problem was introduced in build 3719. It is fixed with QTS 707922 (12.0.1 build 3732).

Thanks to Minghai of the interfaces team for the info.

Former Member
0 Kudos

Problem was solved by EBF 3742. Thank you, Glenn

Answers (1)

Answers (1)

Former Member
0 Kudos

I assume Computer A and Computer B have complete installs with different .NET providers? If, on Computer B, you rename the existing SQL Anywhere .NET provider and copy the .NET provider from Computer A (the 3152 build), does your application now work correctly?

Former Member
0 Kudos

I updated "Computer A" before I read your posting. However, I am now able to verify that I get the same exception on both computers having installed EBF3726

Former Member
0 Kudos

OK. I suspect an issue with the .NET provider. I'll inform the interfaces team.