tags:

views:

122

answers:

5

how i can add the rows in table when the table not have primary key.

+1  A: 

i dont know if this is obvious but maybe you could set a primary key. http://www.functionx.com/vb/adonet/primarykey.htm

also see http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/

Kieran
A: 

You can create a stored procedure to update your table, and execute that to do your updates.

Bennor McCarthy
+6  A: 

As your question's title says, LINQ to SQL can not perform create, update or delete operations on a table without a primary key. It's not possible.

So, you'll need to perhaps use DataContext.ExecuteCommand() to do those things, or better yet, refactor your database so the tables have primary keys.

Andrew Barber
A: 

I may be wrong here, since I have no way to verify right now, but I believe you can tell Linq to Sql that a field is a primary key, even if it's not actually one in the database. This assumes that the data in the field is in fact unique and can be used as a key even if it's not defined as one.

If the table has no primary key, but contains unique data that can be used as a key, then tell L2S in the dbml that this is the primary key.

If the table does not contain unique data that can be used as a key, then you have to write a sproc that deletes the data you want to delete.

Mystere Man
A: 

If you can't set it in the db, set the primary key in the linq2sql designer.

If there is no subset of columns that can be used as primary key, mark them all as part of the primary key.

eglasius
very good idea but i already set in the table
steven spielberg