on 2012 Jun 13 9:42 AM
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:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
71 | |
11 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.