Inheritance of Entity Framework classes

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
matthias.max
Posts: 3
Joined: Fri 21 Nov 2008 12:00

Inheritance of Entity Framework classes

Post by matthias.max » Fri 21 Nov 2008 12:09

Hi all,

I use the entity classes of my edmx file for LINQ queries in my application.
I have come to the point where I need to add additional, business logical functionality/Properties to these classes. I wonder if I should do this via "Inherits" or "Partial Classing". I have tried it with Inherits and it works relatively good and I also would prefer to use "real" inheritance.

The problem now is that I can not add any records with the "AddToTablename" Sub of the entitiy class anymore because the inheriting class is situated in another namespace than the entity class.

Is there a solution like casting the objects (which I tried already but maybe made a mistkae) ?

Here is exmaple code:

Code: Select all

'Generated entity class
Namespace Data
   Partial Public Class DB
       Inherits Global.System.Data.Objects.ObjectContext

       ...
       ...
       ...

   End Class
End Namespace

'Inheritance class
Namespace Business
   Public Class USER
       Inherits MyApp.Data.USER
       
       'Custom functions
       Public Function Check() As CheckFeedback
       ...
       ...
       End Function
   End Class
End Namespace

'Code to add User
Imports MyApp.Business
Dim oUser as USER
...
...
LinqAccess.AddToUSER(oUser)
LinqAccess.SaveChanges()
Thanks for any help!

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 24 Nov 2008 09:38

First of all, we advise to use the partial classes approach as the one recommended by Microsoft.
Also try to change the name of the USER class - VB.NET is case-insensitive programming language,
and that can cause a conflict (User and USER is the same name).

Post Reply