Joel Martinez
Joel Martinez

Reputation: 47809

*Not* using navigation properties with Entity Framework?

Does anyone know if it's possible to not use the navigation properties feature of the entity framework for tables linked with a foreign key?

for example, if my client table has an AddressId, I want that AddressId in my model, I don't want it to have a .Address property. But I have thus far been unable to figure out how to do this.

Upvotes: 7

Views: 3707

Answers (2)

Andrew Timson
Andrew Timson

Reputation: 438

In the designer, you can set the navigation properties as having Private getters/setters. While they will still be there, because Entity Framework (by default) does lazy loading, it won't actually retrieve any data from the database at runtime. And they won't respawn the next time you update the model from the database.

Upvotes: 0

Craig Stuntz
Craig Stuntz

Reputation: 126587

Sure, you can do this. It's just that the designer won't help you very much. Delete the navigation property, and add a scalar property for AddressId. It will work, but you'll have to be careful about hitting Update Model in the designer, as it may try to "fix" things for you. It's worth getting used to editing EDMX; it's not that bad.

Upvotes: 6

Related Questions