Marco Antelmi
Marco Antelmi

Reputation: 293

Saving navigation property in ADO.NET Entity framework

I'm working with ADO.NET Entity Framework. I add a 'User' entity in a database with the following code:

user new_user = new user();
novus_daedalus_dbEntities dbEntity = new novus_daedalus_dbEntities();

new_user.CF = "xyz";
new_user.username = "peter";
new_user.password = "pw";

dbEntity.user.Add(new_user);
dbEntity.SaveChanges();

The CF attribute of the 'user' class is a foreign key to a 'people' class attribute. The database table 'people' has a record with CF='xyz'. When the method 'dbEntity.SaveChanges();' is executed, a new record in the 'user' database table is created without problem. The problem is that the navigation property 'new_user.people' is 'null', even after the execution of 'dbEntity.SaveChanges();'. Is it normal?

Thanks!

Upvotes: 0

Views: 123

Answers (1)

Anri
Anri

Reputation: 6265

It is normal, SaveChanges fills Id properties with database generated id's , but does not make queries to load navigation properties that you might not need, this would not make any sense.

Upvotes: 1

Related Questions