How do i query db.Users with navigation properties? RRS feed

  • Question

  • User-1574857267 posted


    In ASP.NET Identity 2.0, I am trying to extend the build-in Users Class to link to my person table.  There is a similar thread here, but he does not share his solution.

    Here is how i extended the aspnetuser table:

    namespace CAVU.DAL
        public class ApplicationUser : IdentityUser
            public virtual Person Person { get; set; }

    In my controller, I want to do something like this:

    var db = new myContext();
    var users = db.Users.Include(p => p.Person);

    Here is my Error:

    'System.Data.Entity.IDbSet<####.DAL.ApplicationUser>' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Data.Entity.IDbSet<####.DAL.ApplicationUser>' could be found (are you missing a using directive or an assembly reference?)

    I have no trouble inserting data, but when it comes to selecting my data back out, it appears that I don't have the correct interface to join my person table using the navigation property defined above.

    I don't want to add all of the fields directly into the ASPNetUsers table, rather I just want to link to another table: "Person".

    Any Ideas?

    Wednesday, June 4, 2014 12:11 AM


  • User-1574857267 posted

    I was able to get past this error by casting this way:

    var db = new ####Context();
    var x = db.Users as DbSet<ApplicationUser>;
    var user = x.Include("Person").First(u => u.UserName == id);

    I don't know if this solution is the best one or not...but it's working.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 4, 2014 12:53 AM