Architect n-tiered with MVC 4 & EF 5 RRS feed

  • Question

  • User888441741 posted

    I'm working on creating n-tiered application where I will have two separate project

    1) project EF (where it will have all my edmx...)
    2) project MVC 4 (internet application.)

    In my EF i have my `.edmx` file and it generate couple of classes with all props as show below (as sample)...

    // <auto-generated>
    // This code was generated from a template.
    // Manual changes to this file may cause unexpected behavior in your application.
    // Manual changes to this file will be overwritten if the code is regenerated.
    // </auto-generated>
    public partial class Requester
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string MiddleName { get; set; }
    public string LastName { get; set; }

    everything is good so far!!

    `Back to MVC project`

    Now I will be creating a new Controller in my MVC project and when I'm trying to create `Scaffolding` and provide the `Controller` name and `Controller` expects a `Model` so the real question is:

    What `Model` should I be passing here?
    should I have the same class that EF created? or should I be creating another `Model` in my 'Model Folder` (MVC) and bind it? if yes than am I not creating duplicate property if I go ahead and create my same Model in MVC model Folder project?

    What I'm trying to do? : Well my purpose of this exercise is to have my Data Access Layer (DAL) totally separate from MVC project.

    any thoughts?

    Friday, August 30, 2013 10:50 AM

All replies

  • User-488622176 posted

    If you are talking about N-tier, this means you are separating your data access logic from your presentation layer. So adding another model to your MVC project is not the right way to go.

    The first project contains the entities (EMDX creates poco entities), and persistance logic. This can be considered as "data access layer" (where the DbContext is in fact the "layer"). 

    I order to use this from your presentation layer:

    • Reference the DAL project from your MVC project
    • Call de DbContext and use the entities generated by the EDMX directly in your MVC project 
    • Here you'll have a "2-tier" app.

    In order to have a 3-tier app

    • Create a service layer. Each service contains a set of related functionalities (ex: each service implements one use case in your app)
    • The service layer is between the MVC and DAL project. It uses input enities (poco) and return entities (poco) from the DAL
    • The MVC layer only calls services from the service layer, and links UI to service functionalities


    Monday, September 9, 2013 7:40 AM