Click here to Skip to main content
15,921,226 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
QuestionEntity Framework Question Pin
Kevin Marois29-Jun-18 9:31
professionalKevin Marois29-Jun-18 9:31 
AnswerRe: Entity Framework Question Pin
Richard Deeming29-Jun-18 10:02
mveRichard Deeming29-Jun-18 10:02 
AnswerRe: Entity Framework Question Pin
Gerry Schmitz29-Jun-18 11:01
mveGerry Schmitz29-Jun-18 11:01 
GeneralRe: Entity Framework Question Pin
Kevin Marois29-Jun-18 11:26
professionalKevin Marois29-Jun-18 11:26 
GeneralRe: Entity Framework Question Pin
Gerry Schmitz29-Jun-18 11:59
mveGerry Schmitz29-Jun-18 11:59 
AnswerRe: Entity Framework Question Pin
jschell30-Jun-18 5:35
jschell30-Jun-18 5:35 
AnswerRe: Entity Framework Question Pin
Mycroft Holmes30-Jun-18 13:23
professionalMycroft Holmes30-Jun-18 13:23 
QuestionQuestions About Entity Framework and the Repository Pattern Pin
Kevin Marois29-Jun-18 5:28
professionalKevin Marois29-Jun-18 5:28 
I read this article about a basic repository pattern. I understand that a repository would implement
something like this:
public interface IRepository<TEntity> where TEntity : class
{
    TEntity Get(int id);
    IEnumerable<TEntity> GetAll();
    IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate);

    void Add(TEntity entity);
    void AddRange(IEnumerable<TEntity> entities);

    void Remove(TEntity entity);
    void RemoveRange(IEnumerable<TEntity> entities);
}
The author also describes a Unit of Work, which is a class that encapsulates some work to be done and then finalizes all data saving at one time:

(in this example, the "PlutoContext" is an EF data context)
public class UnitOfWork : IUnitOfWork
{
    private readonly PlutoContext _context;

    public UnitOfWork(PlutoContext context)
    {
        _context = context;
        Courses = new CourseRepository(_context);
        Authors = new AuthorRepository(_context);
    }

    public ICourseRepository Courses { get; private set; }
    public IAuthorRepository Authors { get; private set; }

    public int Complete()
    {
        return _context.SaveChanges();
    }

    public void Dispose()
    {
        _context.Dispose();
    }
}
The UnitOfWork class wraps up calls to the repositories for a specific functionality into one class.

1) Would you use this unit of work idea? Why not just make methods on a DAL class to this this, rather than specific IUnitOfWork implementations? I guess you could define specific units of work classes that wrap a specific functionality, but these have to live somewhere and just seem like an additional layer of abstraction that probably isn't needed. What do you think?

2) From what I can see, EF is already made up of units of work. You can do Inserts, Deletes, and Updates all at one time, then call Save. If so, this sounds like a UnitOfWork conecpt isn't needed for EF.

3) When EF queries data, how does it get the data into the Entities? Is it using ADO under the sheets and simply copying the data from a DataTable or DataReader to the entity's properties?

4) Does EF keep track of EVERY property changed, then write out only those changes? Or when Save is called is the ENTIRE entity written to the DB?

Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.


modified 29-Jun-18 12:11pm.

AnswerRe: Questions About Entity Framework and the Repository Pattern Pin
Nathan Minier29-Jun-18 7:34
professionalNathan Minier29-Jun-18 7:34 
GeneralRe: Questions About Entity Framework and the Repository Pattern Pin
Kevin Marois29-Jun-18 7:46
professionalKevin Marois29-Jun-18 7:46 
GeneralRe: Questions About Entity Framework and the Repository Pattern Pin
Nathan Minier29-Jun-18 8:03
professionalNathan Minier29-Jun-18 8:03 
GeneralRe: Questions About Entity Framework and the Repository Pattern Pin
Kevin Marois29-Jun-18 8:27
professionalKevin Marois29-Jun-18 8:27 
AnswerRe: Questions About Entity Framework and the Repository Pattern Pin
Gerry Schmitz29-Jun-18 10:38
mveGerry Schmitz29-Jun-18 10:38 
QuestionMEF based Web API Pin
Mycroft Holmes28-Jun-18 21:12
professionalMycroft Holmes28-Jun-18 21:12 
AnswerRe: MEF based Web API Pin
Nathan Minier29-Jun-18 7:15
professionalNathan Minier29-Jun-18 7:15 
GeneralRe: MEF based Web API Pin
Mycroft Holmes30-Jun-18 13:36
professionalMycroft Holmes30-Jun-18 13:36 
QuestionPython-ic way of efficient TV player app architecture Pin
ninjaef27-Jun-18 0:06
ninjaef27-Jun-18 0:06 
AnswerRe: Python-ic way of efficient TV player app architecture Pin
Richard MacCutchan27-Jun-18 2:44
mveRichard MacCutchan27-Jun-18 2:44 
GeneralRe: Python-ic way of efficient TV player app architecture Pin
ninjaef27-Jun-18 4:36
ninjaef27-Jun-18 4:36 
GeneralRe: Python-ic way of efficient TV player app architecture Pin
Richard MacCutchan27-Jun-18 4:45
mveRichard MacCutchan27-Jun-18 4:45 
GeneralRe: Python-ic way of efficient TV player app architecture Pin
ninjaef27-Jun-18 5:15
ninjaef27-Jun-18 5:15 
GeneralRe: Python-ic way of efficient TV player app architecture Pin
ninjaef27-Jun-18 5:37
ninjaef27-Jun-18 5:37 
GeneralRe: Python-ic way of efficient TV player app architecture Pin
Richard MacCutchan27-Jun-18 6:22
mveRichard MacCutchan27-Jun-18 6:22 
AnswerRe: Python-ic way of efficient TV player app architecture Pin
Gerry Schmitz27-Jun-18 10:50
mveGerry Schmitz27-Jun-18 10:50 
GeneralRe: Python-ic way of efficient TV player app architecture Pin
ninjaef28-Jun-18 6:52
ninjaef28-Jun-18 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.