Homepage | About Me | Testing ASP.net Book | Best Blog Posts | Personal Projects | Follow me on Twitter | GitHub | SlideShare | RSS
Blog.BenHall.me.uk

LINQ Error 'Can't perform Create, Update or Delete operations'

Tuesday, May 29, 2007

I have been playing around with LINQ to SQL and I was receiving an odd error message when inserting a entity into a table. The error was:

Message: Can't perform Create, Update or Delete operations on 'Table(dbo.DocumentRevisions)' because it is read-only.

Type: System.InvalidOperationException
Source: System.Data.Linq
TargetSite: Void Attach(T)
HelpLink: null
Stack: at System.Data.Linq.Table`1.Attach(T item)
at SqlServer.SqlContentProvider.SaveDocument(Document document) in E:\My Documents\Visual Studio Codename Orcas\Projects\SqlServer\SqlContentProvider.cs:line 53
at SimpleWiki.DAL.Tests.DocumentTests.TestInsertingDocument() in E:\My Documents\Visual Studio Codename Orcas\Projects\Tests\DocumentTests.cs:line 28

I thought I had everything correctly, however I forgot to set a primary key in the table, hence Linq was unable to do anything with the object.  So, lesson for the day Linq must have a Primary key for the table :).

Technorati tags: ,

Blogger comments

At 6:06 AM, Blogger zjtopspeed said...
yeah, i encounter the same problem    
At 12:06 PM, Anonymous Anonymous said...
meeee tooo, thx a looot for tip. it's crazy to spend half day with this nuisances, so thx again: for google and your tip    
At 6:22 PM, Anonymous Will Asrari said...
Thanks!    
At 10:42 PM, Anonymous Anonymous said...
Thanks    
At 2:43 PM, Blogger Peleus said...
Very Very Thanks!    
At 3:29 PM, Anonymous Yuvi said...
Thanks for the tip off buddy: You saved the day!    
At 6:48 AM, Anonymous Anonymous said...
My hero... :-) Thanx    
At 8:09 AM, Blogger Ben Hall said...
Thanks everyone, pleased it has been useful for you all.    
At 5:30 PM, Anonymous Anonymous said...
thanks.