EMPLOYEES_TECHNICAL_SKILLS technical_skill_id(PK/FK) employee_id(PK/FK) technical_skill_level_id TECHNICAL_SKILL_LEVEL technical_skill_level_id (PK) skill_level TECHNICAL_SKILLS technical_skill_id (PK) skill_name skill_type
using (knowitCVdbEntities db = new knowitCVdbEntities()) { SPWeb theSite = SPControl.GetContextWeb(Context); SPUser theUser = theSite.CurrentUser; string strUserName = theUser.LoginName; var theEmplDatabaseRem = ( from p in db.EMPLOYEES where p.username == strUserName select p).FirstOrDefault(); _emp = theEmplDatabaseRem; if (_emp != null) { LabelPleaseSelectDbListBox.Visible = false; if (ListBoxDataBase.SelectedItem != null) { string vItem = ListBoxDataBase.SelectedItem.Value; string valueListBox = vItem; int indexOf = valueListBox.IndexOf("-", StringComparison.Ordinal); string valueDatabase = valueListBox.Substring(0, indexOf - 1); EMPLOYEES_TECHNICAL_SKILLS dbRemove = (from p in db.EMPLOYEES_TECHNICAL_SKILLS where p.employee_id == _emp.employee_id && p.TECHNICAL_SKILLS.skill_name == valueDatabase select p).FirstOrDefault(); if (dbRemove != null) { _emp.EMPLOYEES_TECHNICAL_SKILLS.Remove(dbRemove); db.SaveChanges(); ListBoxDataBase.Items.Remove(ListBoxDataBase.SelectedItem); } { LabelPleaseSelectDbListBox.Visible = true; LabelPleaseSelectDbListBox.Text = "You didn't choose anything"; } } // and this result in that i only delete from the first table not the others. and i have also tried with JOIN like this. var dbRemove = (from p in db.EMPLOYEES_TECHNICAL_SKILLS.AsEnumerable() join m in db.TECHNICAL_SKILLS.AsEnumerable() on p.technical_skill_id equals m.technical_skill_id join l in db.TECHNICAL_SKILL_LEVEL.AsEnumerable() on p.technical_skill_level_id equals l.technical_skill_level_id where p.employee_id == _emp.employee_id && m.skill_name == valueDatabase select p).FirstOrDefault();
ON DELETE -> CASCADE
ALTER TABLE [dbo].USER_PHONE WITH CHECK ADD CONSTRAINT [FK_Temp_UsersPhone_Users] FOREIGN KEY([USR_ID]) REFERENCES [dbo].[Users] ([USR_ID]) ON DELETE CASCADE GO
Quote:ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } Specifies what action happens to rows in the table that is altered, if those rows have a referential relationship and the referenced row is deleted from the parent table. The default is NO ACTION. NO ACTION The SQL Server Database Engine raises an error and the delete action on the row in the parent table is rolled back. CASCADE Corresponding rows are deleted from the referencing table if that row is deleted from the parent table.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)