MitchellKrenz
MitchellKrenz

Reputation: 423

How can I get my entity framework Entities object to inherit from DBContext instead of ObjectContext when using the database first approach?

My ultimate goal is to have a dry base repository that I can override if needed, Im going off of an example where the developer had functions like:

Public Overridable Function [Get](id As Guid) As T Implements IRepositoryBase(Of T).Get
        Return Me.mDbSet.Find(id)
End Function

Where mDbSet is from [DatabaseName]Entities.Set(Of T)()

The developer I'm copying used the code first approach so their [DatabaseName]Entities inherits from DbContext whereas I generated mine from the database so it inherits from ObjectContext.

I am looking to make my [DatabaseName]Entities inherit from DbContext without using the code first approach or an alternative way to make the equivalent get by id function using generics.

Thanks in advance!

Upvotes: 0

Views: 582

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

You have to use DbContext Generator T4 template instead of default code (or POCO T4) generation used by Entity designer.

Upvotes: 2

Related Questions