EF5 model in separate project cannot see DbContext methods

I am new to EF and I start with EF5.

Following the recommendations of the Performance Recommendation for Entity Framework 5 , 2.4.2 Moving your model to a separate assembly ... I created a split project (I will call it EfPrj) to manage my Db context (called MyDbContext).

In my domain layer (I will call it DomainPrj) I use entities from EfPrj. The problem is that inside DomainPrj I do not see MyDbContext members inherited from DbContext.

For example, if I want to update the Users table, the code will be as follows:

void UpdateUser(User u) { MyDbContext db = new MyDbContext(); //whatever is needed db.SaveChanges(); } 

But in EfPrj it works without problems. In DomainPrj, I don't see the SaveChanges () member function, getting this error:

 'MyDbContext' does not contain a definition for 'SaveChanges' and no extension method 'SaveChanges' ... could be found (are you missing a using directive or an assembly reference?) 

Update: EfPrj es is just an ORM Database-First project. By default, MyDbContext is defined as an EF5 object: public partial class MyDbContext: DbContext {public MyDbContext (): base ("name = MyDbEntities") {}

So it comes from DbContext and is publicly available. Links DomainPrj EfPrj and MyDbContext db = new MyDbContext() work without problems.

+4
source share
2 answers

Have you tried referencing EntityFramework from your Prj domain?

Since these methods are defined in DbContext, and DbContext is defined in EntityFramework, you must reference it.

In general, if you want to use not only classes, but also delegates, methods, properties, etc., defined in the assembly; You must have a link to this assembly.

+12
source

For me, I had to add Microsoft.Data.Services.Client.dll

0
source

All Articles