Passing Connection String to Entity Framework 6

前端 未结 5 462
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 08:07

I am using EF6 in a class library (database first)

When I followed the wizard and added my tables I selected not to store the connections string in the app.config an

5条回答
  •  时光取名叫无心
    2020-12-14 08:44

    I had this issue as well and used the method from Daniel in the comments.

    Alternatively, you can add it to the .tt file instead of creating another file and using 'partial' – Daniel K Dec 9 '16 at 19:16

    Update *.Context.tt File

    just replace the lines...

        public <#=code.Escape(container)#>()
        : base("name=<#=container.Name#>")
    {
    

    with the following...

    public <#=code.Escape(container)#>()
        : this("name=<#=container.Name#>")
    {
    }
    
    public <#=code.Escape(container)#>(String nameOrConnectionString)
        : base(nameOrConnectionString)
    {
    

    I hope this helps.

提交回复
热议问题