views:

4

answers:

1

Hello, i'd like to create something like wrapper or mayby better word would be "Extension" for generated in EntityFramework model class...

I've got model USER, with password, username etc... and user is in relation many-to-many with some other objects... whatever...

I'd like to create something like this:

class ExtendedUser : USER {
 public void AddObject(Object o) {}
}

But i don't know, is it good idea... I don't know how to create constructor. I'd like do something like this.

User u = ...;
ExtendedUser eu = u as ExtendedUser;

Conceptual i'd like to fetch data from DB and put it into ExtendedUser instance, because this object will have methods to manipulate on this data...

How to do this?

+1  A: 

I believe that the classes generated by the entity framework are partial classes, so you could create another partial class with the same name, within the same namespace, and you should see any extra methods that you add on the user class, e.g.:

partial class User
{
  //Generated code
}

partial class User
{
   public void MyMethod();
}

User u = new User();
u.MyMethod();
Paddy