views:

344

answers:

2

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!

A: 

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.

Regent
I think this works, but now I'm actually questioning whether or not I need to implement a Membership Provider.
Adam Albrecht
It depends on whether or not you need to use that specific User table. In my opinion if you have some thousands of users there already and you can't migrate them then you don't have much choice.But if it is a new project then I'd prefer existing provider...
Regent
A: 

I have a similar problem.

linq has build a class user.

I made a custom class user:inheruser with one property to set.

how do I query user en cast it to inheruser.

When running I get an error "cannot convert user to inheruser"

royd