Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Duplicate FK Record inserted #132

Open
ychuang-tw opened this issue Aug 3, 2019 · 1 comment
Open

Unexpected Duplicate FK Record inserted #132

ychuang-tw opened this issue Aug 3, 2019 · 1 comment

Comments

@ychuang-tw
Copy link

I'm kind of a Postgresql newbie here. Not sure if this is a bug or not.
Scenario:
table Author {ID, AuthorName, BirthYear}
table Books {ID, AuthorID, BookName, PublishYear}

in EF Models
there would be a "public virtual Author Author {get;set;}" statement.

in the past when I use EF for MSSQL
I would do
_book.Author=_author;
db.Authors.Add(_author);
db.Books.Add(_book);
then _book.AuthorID would be automatically filled with ID value of newly added _author record

yet in Postgresql
I find that the same behavior would cause two _author record inserted to the table, with different ID value.

I'm not sure whether there's any way to fix it?

@ychuang-tw
Copy link
Author

I solved this by doing
//_book.Author=_author;
db.Authors.Add(_author);
_book.AuthorID=_author.ID;
db.Books.Add(_book);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant