Click here to Skip to main content
11,718,589 members (86,726 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: LINQ C#4.0

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 2:33am
Edited 15-Jul-12 20:15pm
aspnet_regiis at 15-Jul-12 12:30pm
Does your Stuffs property has SaveChanges() or SumbitChanges() method? like store_dc.Stuffs.SubmitChanges(); ?
loger21 at 15-Jul-12 17:14pm
no. not exist this method .
Nisarg S Shah at 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 at 20-Jul-12 8:48am
My Either Table have the column with Primary key.can you more explain with example code?
Nisarg S Shah at 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. at 16-Jul-12 2:22am
Any exceptions?
loger21 at 16-Jul-12 2:37am
not exception occur
loger21 at 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
0 Sergey Alexandrovich Kryukov 745
1 F-ES Sitecore 245
2 OriginalGriff 220
3 Jochen Arndt 160
4 Maciej Los 130
0 Sergey Alexandrovich Kryukov 1,679
1 OriginalGriff 610
2 Maciej Los 529
3 Richard MacCutchan 460
4 F-ES Sitecore 455

Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 3 Aug 2012
Copyright © CodeProject, 1999-2015
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