-1

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
tereško
  • 58,060
  • 25
  • 98
  • 150
Piort90
  • 11
  • 1
  • 2
  • Since you require UserUser (badly named, call it userUser at the very least) to not be null, get it with Single, rather than SingleOrDefault. – Craig Shearer Oct 13 '13 at 22:24
  • Hey did you see my answer? did it worked? – hjgraca Oct 14 '13 at 21:39
  • possible duplicate of [Non-static method requires a target. Entity Framework 5 Code First](http://stackoverflow.com/questions/13210867/non-static-method-requires-a-target-entity-framework-5-code-first) – Chris Moschini Feb 09 '15 at 14:14

1 Answers1

9

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.

hjgraca
  • 1,695
  • 1
  • 14
  • 29