We have three components: WinForm-Rich-Client, IIS-Webserver using WebApi, entity framework for most of the database queries.
I was given a code base and i am lost. I unterstand that some classes Student
are passed dynamically around using TEntityType. I the msdn docs i read that
you can use this approach when you do not statically know the type of T.
I am trying to understand the lines below, what they do and if the relations between all the interfaces and abstract classes have any benefits
var students = DbEntityAccess.Query<Students>().ToList();
// the query member from Our.DAL.Interfaces.IEntityAccess
IQueryable<TEntTyp>
Query<TEntTyp>(Expression<Func<TEntTyp, bool>> query)
where TEntTyp: class;
DBEntityAccesss
Definition (F12) and implementation for DBEntityAccesss
both lead to
namespace Our.Webservice.Controllers
{
public abstract class SessionBaseController : ApiController
{
protected IEntityAccess DbEntityAccess { get; private set; }
}
}
Sidenote: Visual Studio suggests to rename DbEntityAccess
to GetDbEntityAccess
IEntityAccess
The definition (F12) and the implementation (STRG+F12) of IEntityAccess
are these
// Definition of SessionBaseController.IEntityAccess
namespace Our.DAL.Interfaces
{
public interface IEntityAccess
{
IQueryable<TEntTyp>
Query<TEntTyp>(Expression<Func<TEntTyp, bool>> query)
where TEntTyp: class;
}
}
// Implementation of SessionBaseController.IEntityAccess
namespace Our.DAL.Implementations
{
public class TpdEntities : DbAccess, IEntityAccess
{
// TEntityType shortened to TEntTyp
public IQueryable<TEntTyp> Query<TEntTyp>() where TEntTyp: class
{
return Set<TEntTyp>();
}
}
}
Our.DAL.Implementations.TpdEntities
The class Our.DAL.Implementations.TpdEntities
is implementing the interface Our.DAL.Interfaces.IEntityAccess
(see above) and inherits from DbAccess
which is an abstract class that inherits from System.Data.Entity.DbContext
Our.DAL.Implementations.DbAccess
It is unclear what DbAccess
contributes.
namespace Our.DAL.Implementations
{
public abstract class DbAccess : DbContext
{
// Constructor
protected DbAccess()
: base("name=TPDEntities")
{
Configuration.AutoDetectChangesEnabled = false;
}
}
}
Questions
How is the first part wired up
What does query do, how and when does EF come into play
var students = DbEntityAccess.Query<Students>().ToList();
What does the part
Query<TEntTyp>(Expression<Func<TEntTyp, bool>> query) where TEntTyp: class;
do?- To me it is unclear what Query does?
- How does it query the passed T
TEntTyp
? - What does
Expression<Func<TEntTyp, bool>> query
?
Thanks and regards