Entity Framework - redundant connection string

后端 未结 4 1722
眼角桃花
眼角桃花 2021-02-08 18:57

I\'m using Entity Framework 4 in my project. The Framework has created its own connection string, so my web.config connectionStrings section file looks following:

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-08 19:48

    Although you can create the connection in code, as @gandjustas points out (+1), you cannot get away from having a connection string or EntityConnection.

    This is because it is not actually redundant. Yes, the database connection part is redundant, and @gandjustas showed you how to remove that redundancy. However, the entity framework connection string also contains information about your model, which is not found anywhere in the connection string you wish to keep. This model information has to come from somewhere. Were you to eliminate the entity framework's connection string and use the parameter list constructor on ObjectContext, you would have eliminated all references to the model.

提交回复
热议问题