Click here to Skip to main content
13,350,289 members (70,778 online)
Rate this:
Please Sign up or sign in to 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)
Posted 15-Jul-12 3:33am
Updated 15-Jul-12 21:15pm
aspnet_regiis 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
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. 16-Jul-12 2:22am
Any exceptions?
loger21 16-Jul-12 2:37am
not exception occur
loger21 16-Jul-12 2:41am
when i change the connection string to physical address of mdf file problem solve.
for example : C:\Project\Store

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I think that this line is unnecesary:


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 3 Aug 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100