sql - Three-Tier Architecture Vs Repository Pattern -


i trying use three-tier architecture , repository pattern in asp.net mvc project. in cases, three-tier architecture , repository pattern same. tried study followings make more clear:

the repository pattern

n-tier architecture

after that, i've come following code implementation , expect advices improve implementation in more efficient way:

models - department class:

public class department {    public int departmentid { get; set; }    public string code { get; set; }    public string departmentname { get; set; } } 

interfaces - irepository interface:

public interface irepository {    public int add(student astudent); //for adding students    public int add(department adepartment);  //for adding departments }  

dal - departmentgateway class:

public class departmentgateway : irepository {    /****repository pattern - starts****/    gateway agateway = new gateway();    public int add(department adepartment)    {       agateway.query = "insert departments (code, name) values (@code, @name)";        agateway.command = new sqlcommand(agateway.query, agateway.connection);        agateway.connection.open();        agateway.command.parameters.clear();       agateway.command.parameters.add("code", sqldbtype.nvarchar);       agateway.command.parameters["code"].value = adepartment.code;       agateway.command.parameters.add("name", sqldbtype.nvarchar);       agateway.command.parameters["name"].value = adepartment.departmentname;        int rowaffected = agateway.command.executenonquery();        agateway.connection.close();        return rowaffected;    }    /****repository pattern - ends****/ } 

bll - departmentmanager class:

public class departmentmanager {    departmentgateway adepartmentgateway = new departmentgateway();     public int add(department adepartment)    {       int affect = adepartmentgateway.add(adepartment);        if (affect > 0)       {          return 1;       }       else       {          return 0;       }    } } 

i leaving ui section. trying assure if right way proceed , let me know. thanks.

note: apology ask question. mixing these 2 things , expect advices experts code samples. please don't post links. i've seen some.

n-tier , repository pattern not contradictory. have nothing each other, in fact. n-tier philosophy application should built in layers. it's modularization. repository pattern abstraction, namely abstracting sql queries application code. can both in same application.

however, there's lot of contention around repository pattern. predates orms , there's strong argument made it's redundant orm. entity framework, example, dbcontext unit of work, , each dbset repository. should utilizing here @ point strategy pattern. need interface represents data access, , you're going fill in later implementation (your orm). doesn't affect code here much, though, semantics. bear in mind don't want "repository", , shouldn't build app if you're going have 1 of these implementations per entity or such.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -