Search code examples
c#entity-frameworksqlanywhere

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


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, 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?


Solution

  • It is confirmed that this issue was related to the version of the sybase sql/ef provider I was using. The version 12.0.1.3726 generated this issue. Download new EBF from sybase, 12.0.1.3742 and this specific issue should be resolved.