0

I had this below connection helper class in Visual Studio 2010

public class ConnectionHelper : IConnectionHelper
    {
        public ObjectContext Connection
        {
            get
            {
                if (_connection == null && HttpContext.Current.Items["DbActiveContext"] != null)
                {
                    _connection = (ExampleWebsiteEntities)HttpContext.Current.Items["DbActiveContext"];
                }
                else
                {
                    _connection = new ExampleWebsiteEntities(ConnectionString);
                    HttpContext.Current.Items["DbActiveContext"] = _connection;
                }
                return _connection;
            }
        }
        private ObjectContext _connection;

        public string ConnectionString
        {
            get
            {
                return ConfigurationManager.ConnectionStrings["ExampleWebsiteEntities"].ToString();
            }
        }
    }

This above class works fine in Visual Studio 2010 but giving two errors in Visual Studio 2012

1- Cannot implicitly convert type 'Example.Datalayer.ExampleWebsiteEntities' to 'System.Data.Objects.ObjectContext'

on this line code

_connection = (ExampleWebsiteEntities)HttpContext.Current.Items["DbActiveContext"];

2- 'Example.Datalayer.ExampleWebsiteEntities' does not contain a constructor that takes 1 arguments

on this line code

_connection = new ExampleWebsiteEntities(ConnectionString);

I have double checked everything, but can't figure out what is the issue. Please help me in this. Thank you very much and Regards

Marek Musielak
  • 26,832
  • 8
  • 72
  • 80
aadi1295
  • 982
  • 3
  • 19
  • 47

0 Answers0