c# - Adding data to a dB using EF 6.x -


so have 2 entities corresponding 2 tables in db. name of 2 tables are: doc , users

each entity has properties. relation between doc , users 0 or 1 many. doing following:

doc document = new doc(); ... ... document .users.add(new user{name = "temp", info = "some info.."}); context.addtodocuments(document); context.savechanges(); 

however, entries in doc table added in db. user table in db empty. suggestions?

you should add each entity:

doc document = new doc(); ... ... user usr = new user() {name = "temp", info = "some info.."}; context.users.add(usr); document .users.add(usr ); context.addtodocuments(document); context.savechanges(); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -