tags:

views:

1354

answers:

3

I've created a DBML file for a LINQ to SQL mapping and after dragging all of my tables into the designer surface. In the properties of each table, the "Delete", "Insert" and "Update" are grayed out so they're not editable like they're disabled. I'm not sure why this is. Does anyone know how to make it so that I can insert, update and delete the values inside of those tables?

I also know that I have write permission because I've already written to these tables on the same User ID.

A: 

If you right-click on the table in the designer and choose properties, the Delete, Insert and Update are grayed out. I am not sure if you can supply alternate Delete, Insert and Update methods...

But if your question is about inserting, updating and deleting values in your tables, once you drag a table onto your dbml designer you are able to insert, update and delete using linq in your code. There is nothing else that needs to be done to the dbml.

metanaito
+3  A: 

Do your tables have primary keys? LINQ to SQL won't allow you to change the data if it doesn't have a key to use. I've run into that a lot with legacy systems. A lot of the time the table is using a defacto key, but it's not specifically set up in the database. In those cases, you can just mark the field as primary (in the database) and it should work. Otherwise you may have to add a primary key column just to give LINQ something to use to uniquely identify each row.

gfrizzle
A: 

Without modifying the database you can also address this issue. 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!