Question

I am using ASP.NET Web Forms/C#.

I researched about implementing BLL and DLL in my application.

I found out that many say that using Linq To SQL replaces DAL itself.

So you should be accessing Data and implementing Business Logic inside the BLL class itself.Not sure if it is correct.

Currently I have a class CustomerBLL.I am accessing the data and implementing Business Logic inside it.

So my question is,is it a good approach?

Can I follow this?

Also currently I have only one BLL class , should I use only one or one per .aspx page or group similar pages together.

Here is my CustomerBLL.cs(Just including few functions).

namespace CwizBankApp
{
    public class CustomerBLL
    {
        public string GetDateFormat()
        {
            using (var db = new DataClasses1DataContext())
            {
                var format = db.CODEs.Where(code => code.NAME.Equals("dateformat")).Select(code=>code.DRNAME) .SingleOrDefault();  
                return format;   
            }
        }

        public IList<string> GetAccountTypes()
        {
            using (var db = new DataClasses1DataContext())
            {
                var  acctype = db.mem_types.Select(account=>account.CustCategory).Distinct().ToList();
                return acctype;
            }
        }




        public IList<mem_city> GetCities(int index)
        {
            using (var db = new DataClasses1DataContext())
            {
                var city = db.mem_cities.Where(c => c.state_id.Equals(index)).ToList();
                return city;
            }
        }

        public string InsertDate(string datefield,string dateFormat)
        {
            string dd, mm, yyyy;
            string date;
            string [] split = Regex.Split(datefield, @"/");
            yyyy = split[2];
            if (dateFormat.Equals("British"))
            {
                dd = split[0];
                mm = split[1];
            }
           else
            {
                dd = split[1];
                mm = split[0];
            }

            date = mm.PadLeft(2, '0') + "/" + dd.PadLeft(2, '0') + "/" + yyyy;  
            return date;
        }

        public string RetrieveDate(string datefield,string dateFormat)
        {
            string dd, mm, yyyy;
            string date;
            string [] split = Regex.Split(datefield, @"/");
            dd = split[1];
            mm = split[0];
            yyyy = split[2];

            if (dateFormat == "British")
            {
                date = dd.PadLeft(2, '0') + "/" + mm.PadLeft(2, '0') + "/" + yyyy;   
            }
            else
            {
                date = mm.PadLeft(2, '0') + "/" + dd.PadLeft(2, '0') + "/" + yyyy;   
            }
            return date;
        }
}

Any suggestions are welcome.

Was it helpful?

Solution

In general I separate the BL from the DAL, so that the DAL needs a reference to the BL. This means the BL contains POCO's and an interface that describes the repository/unit-of-work/... So to answer your question, yes, I would still create a DAL which would use L2S.

To answer you second question, I would create one business object per entity that exist in your domain. Usually this matches with the tables in your DAL. The code-behind of your aspx contains the logic of your page, not the business layer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top