How to use DbContext in T4 template?

和自甴很熟 提交于 2019-12-05 20:53:21

I've faced the same error, and the way to get it working was:

  1. Ensure to reference both EntityFramework, and your provider DLLs on Your T4 template; This is enough to get rid of this error.
<#@ assembly name="$(TargetDir)\EntityFramework.dll" #>
<#@ assembly name="$(TargetDir)\EntityFramework.SqlServer.dll" #>
  1. Config files aren't read since T4 runs in a different context; hence you'll need to create a DbContext constructor accepting a connection string; then you pass it while creating the context in T4
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!