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.

  1. is foreign key column set nullable in database?
  2. in model, property of foreign key field nullable
  3. on association, end multiplicity of doguanduser set 0..1

according description, should correct problem.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -