Is there a built in way to delete with Linq to Entites, using the Primary Key.
Currently m work around is to create a Stored Procedure called DeleteTable (table being the table name)
and then in C# LINQ To Entities I just do context.DeleteTable(ID)
Is this the best way? What other options are there?
If you don’t want to go to the database to retrieve all of the object’s fields, you can create a new instance of the class, attach it to a new context, remove that, and save the changes. This lets EF generate the appropriate delete command.
Note: this will throw an exception of you’re trying to delete an object which does not exist. That’s only appropriate if you’re sure the object exists.
Note 2: this assumes you’ve set up your entities so that the generated delete command references no other fields than the ID (meaning no Timestamp properties, or anything similar that would be included in the query)