0

I am new to Entity-framework and MVC and I am trying to make a Data Access Layer (separate layer). I am using VS 2013, Entity-framework 6.1.3 and MVC5. So far I have created Connection Helper class to connect to the database, but I need a little help here.

IConnectionHelper.cs

public interface IConnectionHelper
{
    string ConnectionString { get; }
    ObjectContext Connection { get; }
}

ConnectionHelper.cs

public class ConnectionHelper : IConnectionHelper
{
    public string ConnectionString
    {
        get {
            return ConfigurationManager.ConnectionStrings["databaseEntities"].ToString();
        }
    }

    private ObjectContext _connection;
    public ObjectContext Connection
    {
        get {
                //Need Help what to do here!
        }
    }
}

I just want to learn how to pass connection string name to its constructor. Can you guys please help me, Thanks

aadi1295
  • 982
  • 3
  • 19
  • 47
  • 1
    Don't do this in a web application. An ObjectContext is meant to be created and destroyed after each use. – EkoostikMartin May 28 '15 at 17:52
  • @EkoostikMartin: Ok, can you please suggest me what should I do? Your help is highly appreciable. Thanks – aadi1295 May 28 '15 at 17:53
  • I can't answer that without more context as to what exactly you are building, but you can start here - https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application – EkoostikMartin May 28 '15 at 17:56
  • @EkoostikMartin Thanks for your comment, Actually I wanna learn how to make a separate data layer and use it in MVC5 web application. I am using C# class library to make the data layer, created ADO.net entity data model and now need help with ObjectContext in datahelper.cs – aadi1295 May 28 '15 at 18:01
  • so there is no one, who Can help me? – aadi1295 May 29 '15 at 15:16

0 Answers0