c# - How to stop Entity framework from inserting associated entities? -
i having problems when trying insert entity null associated entities..
i doing :
puser.doganduser = null //doganduser relationship between dog , user context.user.add(puser)
but here getting error saying foreign key iddog not exist in table dog. , well..of course not..i giving null association..then confirmed trying insert associated entities inserting row in dog , passing value in doganduser relationship..which did not throw error , did insert row in relationship..but why? did not explicitly told so..how can stop happening? thanks!
you need check couple of thing correct problem.
- is foreign key column set nullable in database?
- in model, property of foreign key field nullable
- on association, end multiplicity of doguanduser set 0..1
according description, should correct problem.
Comments
Post a Comment