Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Data Model Stored Procedure error - entity command execution exception was unhandled

Firstly, I checked this page but It doesn't seem to help me.

I'm using this edmx file.

Here is my code sample:

private void btnSil_Click(object sender, EventArgs e)
    {
        Int64 isbn = Int64.Parse(dgvKitaplar.CurrentRow.Cells["ISBN"].Value.ToString());

        entity.sp_Sil(isbn);

        entity.SaveChanges();

        dgvKitaplar.DataSource = entity.sp_Update();


    }

Here is my sp_Update() stored procedure

create proc [dbo].[sp_Sil]
        @toDeleteBookId bigint
        as

        begin
        delete from BookInfo
        where ISBN=@toDeleteBookId
        end

What I'm trying to do is deleting a book from the library database via datagridview's current row. First of all, if there is a better/more secure way to do this, I would like to know.

Why am I getting "EntityCommandExecutionException was unhandled"? I know it's quite easy but I'm trying to learn c# and .net environment.
Thanks in advance.

@I guess it's because of something about data tables but I still can't find what it is.

like image 917
Burak Karakuş Avatar asked Jun 15 '26 03:06

Burak Karakuş


1 Answers

If the data model says its a "one to one" between BookInfo and Book, then you will not be able to delete the BookInfo without deleting the Book.

To solve this, update the data model to be "zero to one". Then you should be able to delete the BookInfo. HTH.

like image 69
Carl Prothman Avatar answered Jun 17 '26 15:06

Carl Prothman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!