Two suggestions for Entity Frameworks

David Thielen 2,796 Reputation points
2023-04-19T16:14:25.1666667+00:00

I have no idea where to post suggestions so doing so here.

  1. I have a record with a nullable FK. EF threw an exception building the database because that FK could lead to a cyclical cascade on deletes. The issue was not with deleting the record, it was with deleting the record the FK pointed to.
    The thing is, deleting that pointed to record is, by definition in the design of my code, a bug. So what is needed is the ability to specify that deleting a record pointed to by that FK is not allowed. And if that is attempted, an exception should be thrown at run time. But with this restriction, then the database can be built.
  2. I have a model (Event) that numerous models (State, County, etc.) have a collection of. EF won't build the database because State also has a collection of County and so it's worried deleting State will delete its Events, its Counties, and that Counties Events - which might be the same Event.
    What's needed here is a way of telling EF that a given Event will be in exactly 1 collection. An evetn in State.Events cannot also be in County.Events. I can accomplish this with fluent commands and overriding SaveChanges(Async). But why make us jump through hoops when it could be a simple fluent declaration? thanks - dave
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
726 questions
{count} votes