Non-static method requires a target

asp.net-mvc asp.net-mvc-4 entity-framework

Question

Could you help me on this code

Profile ProfileDoctor = _context.Profiles.SingleOrDefault(p => p.ProfileId == id);
Users UserUser = _context.Users.SingleOrDefault(d => d.UserName == User.Identity.Name);
Profile UserProfile = _context.Profiles.Where(t => t.UserId == UserUser.UserId).SingleOrDefaul(); <--- Non-static method requires a target 
Meetings meeting = new Meetings
1
-2
10/14/2013 8:07:34 PM

Accepted Answer

You are getting a null reference exception. It is called a non-static target exception since LINQ uses reflection. Check if that line does not return null. My guess would be that UserUser is null when trying to call the UserUser.UserId property.

7
10/13/2013 10:23:29 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow