A specified Include path is not valid. The EntityType does not declare a navigation property with the name *

Viewed 63887

I'm trying to get data from a LocalDb into my MVC Controller. I tried this:

UsersContext db = new UsersContext();
var users = db.UserProfiles.Where(u => u.UserId == WebSecurity.CurrentUserId)
                           .Include(u => u.LastName).ToList();

It returns this error:

A specified Include path is not valid. The EntityType 'ChatProj.Models.UserProfile' does not declare a navigation property with the name 'LastName'.

Here is a picture of my localDb and model.

Any idea why it's not working?

5 Answers

In my case I solved it as the following

the code with the error :

LabResults = db.LAB_RESULTS.Where(o => o.ORDER_ID == id)
.Include(p => p.LabTests).ToList()

then I removed .Include :

LabResults = db.LAB_RESULTS.Where(o => o.ORDER_ID == id).ToList()
Related