简体   繁体   中英

What is dalAccess supposed to do in ASP.NET?

I am a bit new to the ASP.NET MVC framework making the move from Ruby on Rails 3 and it's ActiveRecord. Please help me understand the place of dalAccess in the MVC.

[HttpGet]
    public ActionResult copyCampaign(int Id)
    {
        DALAccess dalaccess = new DALAccess();
        //string newid = dalaccess.CopyOffer(Id);
        string newid = dalaccess.CopyOfferByCampaignId(Id);

        string type = PrepareOffer4Edit(newid);
        if (type == "bundle")
            return RedirectToAction("bundleStep1");
        else if (type == "scratchOff")
            return RedirectToAction("scratchOffStep1");
        else
        {
            return RedirectToAction("CampaignMgmt", "CampaignMgmt");
        }
    }

The purpose of having s DAL (Data Access Layer) is the concept of Separation of Concerns . This also works for the Single Responsibility Principle .

The DAL provide a way for you to retrieve your data objects from their source without having to worry about where the data comes from or how to transform it. This allow you to create tests specifically for your data access functionality to help identify issues.

The separation also comes in handy if and when you need to write a another application (or let's say a 2nd front end) that uses the same data.

It depends. I am not familiar with Ruby's active record, so I can not give you parallels.

In .Net Data access is usually a lower layer in the application. This varies, but usually as the application grows, you'll find the data layer more isolated. In smaller apps this is not much of a concern.

As of now ORM's have become the way of data access. There are two prevalent ORM's in .NET: Entity Framework (Microsoft) and nHibernate (open source). Both have merits, both can get the job done and both have decent documentation. EF is a bit easier to pick up, as it flows with .Net nicely. nHibernate is a bit more flexible espically as complexity increases. nHibernate has been to generate better SQL. Although, Microsoft put a lot of work into cleaning up the SQL generation in the latest release of EF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM