Click here to Skip to main content
15,444,523 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:

I am trying to delete record from an entity from my datacontext and use SubmitChanges() method to save this. so I used cascading deletes rule .but not working this and not save any change in database table.( used linq to sql class (dbml))
Here's the code that is supposed to delete:


  <add name="Store.Properties.Settings.StoreConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Store.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" />
  <add name="StoreEntities" connectionString="metadata=res://*/StoreEntityModel.csdl|res://*/StoreEntityModel.ssdl|res://*/StoreEntityModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\Store.mdf;integrated security=True;connect timeout=30;user instance=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

StoreDataContext store_dc = new StoreDataContext(constr);

    foreach (StuffRegTable stf in DtgridTbl)
        if (stf.Checked == true)
            var deletobject = (from rec in store_dc.Stuffs
                               where rec.BareCode == stf.BarCode
                               select rec).Single();


catch(Exception ex)
Updated 15-Jul-12 20:15pm
bbirajdar 15-Jul-12 12:30pm    
Does your Stuffs property has SaveChanges() or SumbitChanges() method? like store_dc.Stuffs.SubmitChanges(); ?
loger21 15-Jul-12 17:14pm    
no. not exist this method .
Nisarg S Shah 18-Jul-12 9:02am     CRLF
Either the Table will not be having the column with Primary key or while deleting the record you might have forgot to select the primary key. It will still allow you to select the data but insertion or deletion or updation will not take place until and unless the primary key column is used to perform any of the above said transactions
loger21 20-Jul-12 8:48am    
My Either Table have the column with Primary key.can you more explain with example code?
Nisarg S Shah 25-Jul-12 6:50am    
All i mean is that there can be a possibility that the table might not have any primary key being defined or may be possible that the primary key is not being used while deleting the record.

1 solution

I think that this line is unnecesary:

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900