So I created a view model that holds all the properties of both models.Created pk nd fk keys in tables.
Scaffolded utilizing ef core db first.. Index page is working fine.but while su bmitting data into db two tables separately, error show up tat 2nd table can't be traced since it dies not have pk key.But I hv assigned fk in 2nd and pk in primary table.
Then i commented a line in dbcontext class auto-generated fluent api code on
//model.hasKey(2nd table).
Now submitting data to two tables is working.i assigned 2nd table Id to the primary tile Id statically inside controller.
Is this right approach? why pk and fk relationships not works? Pls somebody guide me
im not understaging a bunch of things; i assume you are using code first approach how come the two tables had not a relationship before? are you mapping to a dto for the view? do you have both the fk and the inverse property in the relation?
I m using database first approach i already build tables and pk and fk key in sql server then only I created project in vs and scaffolded tables in package manager console in the auto-generated code, second model class has Navigation property . But still error displays when create Action is posted
Обсуждают сегодня