简体   繁体   中英

Why can't I access the value(s) of foreign key field(s) when using Entity Framework?

I have a user table in my database that looks like this:

public class tblUser{
    public int id{ get; set; }
    public string name{ get; set; }
    public int? customer_id{ get; set; }
}

There is a foreign key on the customer_id column that links to the tblCustomers table where I can get extended information IF the user is in fact a customer.

When I was using Linq-to-SQL objects, I used to ensure that the user was linked to a customer by testing customer_id.HasValue , but having now changed to Entity Framework, I can't even see the customer_id property - am I doing something wrong?

Thanks

The Entity Data Model Wizard gives you the option Include foreign key columns in the model . This is off by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM