LINQ DBML won't let me insert, update, delete or select data from any tables? What for?

I created a DBML file for LINQ to SQL mapping and dragged all my tables onto the designer surface. In the properties of each table, "Delete", "Insert" and "Update" are grayed out, so they are not edited as if they were disabled. I don't know why this is so. Does anyone know how to make it so that I can insert, update and delete values ​​inside these tables?

I also know that I have write permission because I already wrote these tables on the same User ID.

+1


source to share


3 answers


Do your tables have primary keys? LINQ to SQL won't let you modify data if it doesn't have a key to use. I've worked a lot with legacy systems. The defacto key is used many times in the table, but it is not specifically configured in the database. In such cases, you can simply mark the field as primary (in the database) and it should work. Otherwise, you might have to add a primary key column to give LINQ something to use to uniquely identify each row.



+4


source


If you right click on the table in the designer and select properties, then Delete, Insert and Update will be grayed out. I'm not sure if you can provide alternative delete, insert and update methods ...



But if you are asking a question about insert, update and delete values ​​in your tables, once you drag the table into your dbml constructor, you will be able to insert, update and delete using linq in your code. There is nothing to do in dbml.

0


source


Without changing the database, you can also fix this problem. Set the primary key in the DBML file and it will work fine. LINQ just needs to know the defacto key. You can also set multiple columns as keys.

LINQ is great!

0


source







All Articles