4imble
4imble

Reputation: 14416

Can you lazy load when model has associations, but the database does not?

I am working on an old database, that i do not want to touch or modify in any way if possible. I want to build a new application that uses it's data but the database has no actual relations despite having primary and foreign keys linking tables.

If i import these tables into an Entity Framework model and add the associations manually, will i be able to use things such as lazy loading and linq?

Many thanks, Kohan

Upvotes: 0

Views: 98

Answers (1)

Ronald Wildenberg
Ronald Wildenberg

Reputation: 32094

This is definitely possible. Entity Framework simply generates SQL queries containing joins or where clauses that reference columns that you define in your conceptual model as foreign keys. The generated SQL is directly executed by the database.

Primary and foreign keys are only in your database for referential integrity. As a very simple test you can execute a SQL statement directly in your database that joins two related tables that do not have a foreign key relationship. You'll see that the query simply works. Entity Framework does exactly the same when you correctly define the relationships in your model.

Upvotes: 3

Related Questions