3

I have a solution consisting of 4 projects. MVC, WCF, Business LYR, DataAcess. I am using entity framework for database transaction. My requirement is that i want to fetch the entity connectionstring only from MVC webconfig without refering in APP.cofig of acess layer. Is it possible in this scenario?

While I tried the following code I got an error.

    this.ConnectionString="data source=cmh-sosql;initial catalog=Student;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework";

            System.Data.SqlClient.SqlConnectionStringBuilder scsb = new System.Data.SqlClient.SqlConnectionStringBuilder(this.ConnectionString);

EntityConnectionStringBuilder ecb = new EntityConnectionStringBuilder();
ecb.Metadata = "res://*/schoolModel.csdl|res://*/schoolModel.ssdl|res://*/schoolModel.msl";
ecb.Provider = "System.Data.SqlClient";
ecb.ProviderConnectionString = scsb.ConnectionString;

using (SchoolDB schoolDB = new SchoolDB(ecb.ConnectionString))

Error: The entity type student is not part of the model for the current context.

2
  • can you explain why this should needed ? i.e. not getting from App.config ? Commented Dec 15, 2012 at 12:05
  • I need to take the second connection from database of the first connection. That was my issue... Now solved... Commented Dec 16, 2012 at 5:12

1 Answer 1

2

You are absolutely correct. I got the solution. There is no need to keep any string in webconfig for reference to a entity model. We can use the above code for reference it. But the change is to configure the context object.

public SchoolDB(string  connectionString)
        : base(connectionString)
    {
    }
We need to change the constructor also by this format. 

thanks Sampath

Sign up to request clarification or add additional context in comments.

1 Comment

Glad to help to you.But please accept your answer as the solution.Then others can quickly identified the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.