tags:

views:

359

answers:

5

I'm using Linq to SQL for the Database operations, and am trying to perform insert operations in a VIEW, It throws the Error,

XXt threw exception: System.InvalidOperationException: Can't perform Create, Update or Delete operations on 'Table(XXX)' because it has no primary key.

How to use LINQ to insert a record into View using C#?

Thanks.

A: 

Add a primary key to the SQL table in your database, then delete and recreate the table in the .dbml file.

Tim S. Van Haren
A: 

I assume you mean that instead of trying to insert a row into a View, you are trying to insert a row into a table. You do not insert rows into Views.

Having said that, L2S requires your tables to have primary keys, as the error message indicates. Once you create a primary key, and update your .DBML accordingly, you should be fine.

Randy

Randy Minder
+1  A: 

You cannot insert into a VIEW. You can only insert into a table.

Matt Joslin
A: 

Actually you can insert into a view..if the underlying view has one table then you can insert into it.

If it has more than one table..then u can use instead of triggers;

Also I have inserted a record into a view..in linq to sql. (i have just started learning linq myself).

I had to create a primary key on a view. using the designer and then set the auto sync for that field to never. that should do the trick..

ahmed
A: 

This is a link that provide a good workaround for inserting data into table without primary key.

http://www.a2zmenu.com/LINQ/Cannot%20perform%20Create,%20Update%20or%20Delete%20operations%20on%20Table(Employee)%20because%20it%20has%20no%20primary%20key.aspx

rs.emenu