我試圖從一個LocalDb獲取數據到我的MVC控制器。我嘗試這樣做:指定的包含路徑無效。該EntityType不聲明導航屬性的名稱*
UsersContext db = new UsersContext();
var users = db.UserProfiles.Where(u => u.UserId == WebSecurity.CurrentUserId)
.Include(u => u.LastName).ToList();
它返回此錯誤:
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.
任何想法,爲什麼它不工作?
乾杯m8,很棒的答案! – JazzMaster
@JazzMaster歡迎:)也考慮閱讀[導航屬性](http://msdn.microsoft.com/en-us/data/jj713564.aspx) –
@SergeyBerezovskiy,你介意看看我的問題嗎? https://stackoverflow.com/questions/28988951/export-to-excel-linq-include-foreignkey-values-in-tolist –