1

I'm working on a WPF system which hooks onto an old legacy database using the Entity Framework. We hook onto a backup of the live data when debugging and an empty database to run tests against. I'm receiving the following error only when trying to delete from a backup of the live data.

This code:

License license = ReadLicense(id);
entities.DeleteObject(license);
entities.SaveChanges();

produces this SQL:

exec sp_executesql N'delete [dbo].[Product]
where ((([Group_ID] = @0) and ([Parent_ID] = @1)) and ([Prod_ID] = @2))',N'@0 nvarchar(32),@1 nvarchar(32),@2 nvarchar(32)',@0=N'someIdValue1',@1=N'someIdValue2',@2=N'someIdValue3'

which in turn produces this error:

Msg 208, Level 16, State 1, Procedure TrackDeletedProduct, Line 4. Invalid object name 'DeletedRecords.dbo.Product_Deleted'.

If you change the generated SQL to a 'select' query it returns a row so, 'ReadLicense' is returning a valid entity. I can't really understand why this doesn't work, especially when it's only against live data. The 'License' entity is one of two inheriting from a base 'Product' entity.

Cheers.

1 Answer 1

5

From what I can see, it would appear as if your table Product has a trigger on it that will fire when you delete a row, and which calls that stored procedure TrackDeletedProduct.

That procedure will (just guessing here) try to copy the product entry to the Product_Deleted table in the DeletedRecords database, but fails on that - either that other database or the table don't seem to exist.

So I don't think this has really anything to do with ADO.NET Entity Framework or LINQ-to-Entities, but a lot with SQL Server - check your backend database configuration!

Marc

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much man, didnt think of table triggers. FYI the empty version of the db is created from a cut down version of the backup's creation script, i found that out since showing you're solution to my co-worker who did that. So the trigger simply wasn't in there. Rekon i should edit the tags?? Might help others more...
Glad I could help - I would leave the tags as they are - no problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.