I have a legacy database design that I'm trying to work around with EF 4. Essentially, I have two tables that reference each other causing issues when trying to add new entries.
My structure is this:
CREATE TABLE [dbo].[Account] (
[AccountId] INT IDENTITY (1, 1) NOT NULL,
[PrimaryPersonId] INT NULL,
[other columns])
CREATE TABLE [dbo].[Person] (
[PersonId] INT IDENTITY (1, 1) NOT NULL,
[AccountId] INT NOT NULL,
[other columns])
Person has a foreign key to Account (AccountId) and Account has a foreign key to Person (PrimaryPersonId). When creating a new account and person, this is obviously a problem. Currently the solution is to use an insert trigger on the Person table that updates the Account table with a new PrimaryPersonId when a person is created.
I'd like to get away from needing triggers and bring this code into the model if possible so there's less "magic" happening. Is there a good way to do this with EF 4?