none
Providing connection string to an EF 5.0 model RRS feed

  • Question

  • Trying to upgrade to EF5 and I have an issue with not having a model constructor which allows a connection string.

    In the older EF Designer.cs code their was:

       public CVEntities() : base("name=CVEntities", "CVEntities")
            {

    and also

        public CVEntities(string connectionString) : base(connectionString, "CVEntities")
            {
                this.ContextOptions.LazyLoadingEnabled = true;
                OnContextCreated();
            }

    Now in EF 5 their is only CVEntities()

    In my class I need to create a model using a constructor

     CVEntities ctx =   new CVEntities(this.ConnectionString);

    How can you do this in EF5?

    Thursday, August 30, 2012 8:36 PM

Answers

  • Hi chuck02323;

    It appears that in VS 2012 when using the designer they are setting "Code Generation Strategy" to None and are using T4 templats to create the model which seems to have only one constructor. You can still use the default code generation by setting "Code Generation Strategy" property in the designer to default and deleting the two files under the edmx node in Solution Explorer with the extension .tt and then recompile and at this point things should be as in earlier version in EF. Why and what is the differences with the new settings besides ObjectContext constructors I do not know.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, August 31, 2012 3:06 PM

All replies

  • Hi chuck02323,

    Welcome to MSDN Forum.

    Could you please clarify what the version of .NET you are using? How the Context generated? By template or default?

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Friday, August 31, 2012 2:08 AM
    Moderator
  • VS12, .net 4.5, EF5

    I created a class that needs to use a connection string.

    The code in the class looks like this:

     CVEntities ctx =   new CVEntities(this.ConnectionString);

    However, it errors because now their is only a () constructor.
    The model was created using the designer.

    Friday, August 31, 2012 1:25 PM
  • Hi chuck02323;

    It appears that in VS 2012 when using the designer they are setting "Code Generation Strategy" to None and are using T4 templats to create the model which seems to have only one constructor. You can still use the default code generation by setting "Code Generation Strategy" property in the designer to default and deleting the two files under the edmx node in Solution Explorer with the extension .tt and then recompile and at this point things should be as in earlier version in EF. Why and what is the differences with the new settings besides ObjectContext constructors I do not know.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, August 31, 2012 3:06 PM