In a database, I have a 1:n connection between two tables: Personnel (1): Role (n) Role's idEmployee foreignKey
I want to write a Linq query that would get each position for a certain client. I want to create something similar to this:
var myQuery = from r in Role where r.idEmployee == someId select r;
But idEmployee is not a property of r! How can I determine the foreign key's value?
If you use
This will at least provide you with what you require: Entity Framework foreign keys
If you use
Your issue is more significant since the model doesn't display any foreign keys. You must repeat the process.
collection looking for a good bargain. However, I believe that this would simply return the value of a foreign key and not function in a query (since EF would not know how to translate it to SQL query).
But why not just utilize your foreign keys if you have them?
to maneuver to
and verify the value there?
var myQuery = from r in Role where r.Employee.idEmployee == someId select r;
Make sure to have the choice if you're utilizing EF 4.0 (.NET 4.0), a database-first programming model, and an EDMX model (visual designer).
Include foreign key columns in the model
When you include tables to your EDMX model, make sure:
If this option is not selected, EF 4.0 will function similarly to EF 1.0/3.5 (in.NET 3.5), including a navigation property but treating the foreign key column as a distinct column.