Home > Net >  How to find entity from context with two foreign keys?
How to find entity from context with two foreign keys?

Time:04-12

I want to delete an entity, which has 1 primary key and 2 foreign keys. The problem is I only know the 2 foreign keys. Is there an Methode or something else, to find the entity, which I want to delete?

Here is my entity:

enter image description here

And here is my method:

enter image description here

In my Database:
BookmarkId = 7,
SeriesId = 1,
UserId = 1

But the entity (bookmark) is:
BookmarkId = 0,
SeriesId = 1,
UserId = 1

because I dont know the BookmarkId for every single one.

Hope there is enough information and somebody knows what I need to do.

CodePudding user response:

This is a strong indication that Bookmark has the wrong key. If its key were simply (SeriesId, UserId) then you could create a stub entity, mark it as Deleted and SaveChanges.

As it is you must query the Bookmark from the database to discover its BookmarkId.

  • Related