近期了解MVC4的時(shí)候弄了1個(gè)簡(jiǎn)單的小工程,使用Entity Framework作為Model,F(xiàn)5啟動(dòng)調(diào)試運(yùn)行的時(shí)候沒有問題,但是發(fā)布到IIS以后訪問就報(bào)錯(cuò)
毛病信息以下:
The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application.
很奇怪,搜索了1下,找到1個(gè)老外的帖子,戳這里
解決方案以下:
在EF的上下文代碼CS文件(Model1.Context.cs)中添加這個(gè)方法
不明所以,具體緣由還是不清楚,這個(gè)方法也歷來未被調(diào)用過,但是。。。好用了!
此解決方案還需要后續(xù)進(jìn)行觀測(cè),畢竟修改的是根據(jù)數(shù)據(jù)庫生成的文件。
還有1種方案我沒有嘗試,可以強(qiáng)迫部署EntityFramework.SqlServer.dll這個(gè)文件到輸出目錄,有興趣的可以嘗試。