I’m currently working in asp.net mvc 4 with EF5 and I’m trying to get my Dependency Injection to work with Ninject.
I’ve made 4 different projects in my solution:
- Gui -> contains my MVC-project
- BusinessLogic -> BusinessLogic
- DataAccess -> my edmx-file and Repository (references Common)
- Common -> Models, ViewModels and IRepository.
Now I’m trying to write this:
IRepository:
IQueryable<PictureSource> PictureSource { get; }
Repository:
IQueryable<PictureSource> IRepository.PictureSource
{
get { return context.PictureSource }
}
Now the problem is I can’t call on PictureSource in my IRepository because it’s an Entity from my EF, which is in my DataAccess. I’ve tried using automapper the following way in my Repository:
public IQueryable<PictureSourceModel> PictureSource()
{
Mapper.CreateMap<List<PictureSource>, List<PictureSourceModel>>();
return Mapper.Map<List<PictureSource>,List<PictureSourceModel>>
(context.PictureSource.ToList());
}
This gives errors about it beind a dbSet.
Any hints?
If you can’t access some Model classes from your IRepository then you didn’t apply your structure.
The
PictureSourceModelclass and all other Entities should be in your Common Project.Then “as expected” all other projects will get access to these classes.
To be able to separate EF Entities to another Project you may consider to use Visual Studio Extension called “Ef DbContext Generator“.
If you want more help tell me.
BTW: Try not to use AutoMapper in DAL. It should used in Gui project.
Update
To separate Entities to POCO classes
Generator“.
Code Generation Item”