problem of cascade delete in entity framework

According to cascade deleting, i wrote below codes but there is an error : An error occurred while updating the entries. See the inner exception for details.

 using (doctorEntities de = new doctorEntities())
            {
                var delete_base_print = (from Table_infobase_print tip in de.Table_infobase_print
                                         where tip.ID == ((Doctor.Table_infobase_print)(datagrid_table_infobase_print.SelectedItem)).ID
                                         select tip).First();
                de.DeleteObject(delete_base_print);
                de.SaveChanges();
            }

<Association Name="FK_Table_infodetail_print_Table_infobase_print">
      <End Role="Table_infobase_print" Type="doctorModel.Table_infobase_print" Multiplicity="1">
        <OnDelete Action="Cascade" />
      </End>
      <End Role="Table_infodetail_print" Type="doctorModel.Table_infodetail_print" Multiplicity="*" >
      </End>
      <ReferentialConstraint>
        <Principal Role="Table_infobase_print">
          <PropertyRef Name="ID" />
        </Principal>
        <Dependent Role="Table_infodetail_print">
          <PropertyRef Name="ID_infobase" />
        </Dependent>
      </ReferentialConstraint>
    </Association>

Answers


<OnDelete Action="Cascade" />

This only covers the loaded entities in your object context (it will cascade deleted related entities), but not the database itself. Make sure you have set up cascaded delete constraint on the database for the corresponding table.

Edit:

To set cascading deletes in SQL Server, set the delete rule for the foreign key relationship to cascade. For this open up SQL Server Management Studio, open up the table in question for design and show the foreign key relationship. Set Cascade as Delete Rule within the INSERT and UPDATE specification.


Need Your Help

Limit Exceeded: Email Recipients Per Message. but only 67 recipients?

google-apps-script gmail quota

I keep getting Limit Exceeded: Email Recipients Per Message. when trying to use the forward command in my google script. I'm forwarding a message with 67 people BCCed and one person CCed, to field

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.