Search code examples
asp.net-mvclinq-to-sqlasp.net-membershipmembership-providermembershipuser

Make a Linq-to-SQL Generated User Class Inherit from MembershipUser


I am currently building a custom Membership Provider for my Asp.net MVC website. I have an existing database with a Users table and I'm using Linq-to-Sql to automatically generates this class for me.

What I would like to do is have this generated User class inherit from the MembershipUser class so I can more easily use it in my custom Membership Provider in methods such as GetUser. I already have all the necessary columns in the table.

Is there any way to do this? Or am I going about this the completely wrong way?

Thanks!


Solution

  • Usually code generation tools creates so called partial classes, like:

    public partial class User
    {
        // class definition here
    } 
    

    This means that you can extend definition of that class somewhere within the same namespace like that:

    public partial class User: MembershipUser
    {
        // if MembershipUser doesn't have parameterless constructor then you need
        // to add here one
    }
    

    And then you'll have User class inheriting from MembershipUser.