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
Post a Comment