Linq to Entities (EF): How to get the value of a FK without doing the join

loaiweb

New Member
I'm using the Linq to Entities. I've got my main table, Employee setup with a field named vendorID. Vendor ID is a foreign key into the Vendors table.As it is right now, the Employee object does not directly expose the vendorID. Instead, I can only access it this way:\[code\]var employee = (from e in context.Employees.Include("tbl_vendors") where e.employeeID = 1 select e).FirstOrDefault();//this gets the vendor IDint vendorID = employee.tbl_vendors.vendorID;\[/code\]That is just fine and dandy, but it is extra work on the database because it is forcing a join where none is needed. Is there a way to get that key value without being forced to do a join to the tbl_vendors table?
 
Back
Top