Page 1 of 1

Create, delete and update problem

Posted: Wed 21 Jul 2010 15:36
by imre.dudas
Hello,


I generated DataContext models from PostgreSQL database with Entity Developer new version. I can't insert, update and delete all of my tables in my program.

AuthorizationDataContext dc = new AuthorizationDataContext(connectString);
FirstChars f = new FirstChars();
...
dc.FirstChars.InsertOnSubmit(f);

And give me an exception:
System.InvalidOperationException: Can't perform Create, Update or Delete operations on 'Table(FirstChars)' because it is read-only or does not have identity members.
Devart.Data.Linq.Table.l()
Devart.Data.Linq.Table.c(Object A_0, Boolean A_1)
Devart.Data.Linq.Table`1.InsertOnSubmit(TEntity entity)

FirstChars is a simple table with three character varring fields: FirstThreeCharacters, SoftwareName, SoftwareVersion.

The role that i used in ConnectString have got privileges these operations in database.

Best Regards:
Imre

Posted: Thu 22 Jul 2010 15:38
by AndreyR
Please check that your FirstChars entity has an Entity Key defined. This is usally a reason for such errors. Entities in LINQ to SQL should have Entity Keys defined to perform CUD operations with them.

Posted: Thu 22 Jul 2010 16:32
by imre.dudas
Thank you. It's ok.

If i remember good, in the last versions, entity key checked automatically.

Posted: Mon 26 Jul 2010 14:22
by AndreyR
Could you please post here the script of the table you have encountered an error with the wrong Entity Key generation?

Posted: Sat 31 Jul 2010 18:50
by imre.dudas
AndreyR wrote:Could you please post here the script of the table you have encountered an error with the wrong Entity Key generation?
I created a test on my server, and create a model. You can access to my database with this model. It's a simple test, but the entity key is false default.
The table creation SQL script is
create table testtable
(
test_id serial,
test_note varchar(100)
);

http://dl.dropbox.com/u/3968115/Test.zip

Regards:
Imre

Posted: Mon 02 Aug 2010 16:15
by AndreyR
Thank you for the report, we are investigating the reasons of this issue.
I will notify you about the results of our investigation.

Posted: Fri 06 Aug 2010 14:08
by AndreyR
This behaviour is designed. Unlike Entity Framework, LINQ to SQL Entity does not need to have Entity Key by default.
In Entity Framework Entity Key will be inferred automatically form not-nullable columns.