using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace TZONE.DataAccess
{
    public class DataAccessFacadeBase
    {
        public string ConnectionString
        {
            get
            {
                if (ConfigurationManager.ConnectionStrings["DB"] == null ||
                    String.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["DB"].ConnectionString) == true)
                {
                    throw new InvalidOperationException("The default connection string does not exist or is empty");
                }
                return ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
            }
        }

        private DataAccessEntitiesDataContext m_dataContext;

        public DataAccessEntitiesDataContext DataContext
        {
            get
            {
                if (m_dataContext == null)
                {
                    m_dataContext = new DataAccessEntitiesDataContext(ConnectionString);
#if DEBUG
                    m_dataContext.Log = Console.Out;
#endif
                }
                return m_dataContext;
            }
        }
    }
}
