EF connection string as DbContext constructor argument

前端 未结 4 1066
北海茫月
北海茫月 2020-12-19 07:31

I have seen some code sample that put an entity framework connection string as a constructor argument when creating a new DbContext. But when I added a new ADO.NET entity da

4条回答
  •  無奈伤痛
    2020-12-19 07:50

    The new data model wizard adds a connection string to your config file and the code generation is setup to create a context with a parameterless constructor that then calls the base constructor with "name=foo" so that the connection string in the config file will be used.

    If you want to explicitly pass a connection string to the constructor (instead of reading it from config) then you can use the fact that the context is a partial class to add that constructor. You could also modify the T4 code generation template to change the constructor that is generated.

提交回复
热议问题