No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0'

后端 未结 12 2302
失恋的感觉
失恋的感觉 2020-12-05 22:44

I got the following error when I used sqlce 4.0 with entityframework 6.0

No Entity Framework provider found for the ADO.NET provider with invariant name \'Sy         


        
12条回答
  •  猫巷女王i
    2020-12-05 23:46

    the solution provided is correct but it does not explain why EF need this assembly. Here is Why...

    By default EF's configuration allow you to have a "defaultConnectionFactory" uder entityFramework section. This default factory is configured to "LocalDbConnectionFactory" and its param is "mssqllocaldb".

    This factory internally requires "SqlServerCe.4.0" i.e. "SqlServerCompact".

    The error happens only if the EF uses its default connection string in DbContext. If EF is provided with some other specified Connection string in your config then this error does not appear. Because EF by default uses the default connection factory.

    once you install "SqlServerCe 4.0" the configuration of EF is changed and "LocalDbConnectionFactory" and its param is "mssqllocaldb" are replaced with "SqlServer Ce 4.0". and EF runtime is also able to find the SqlServerCe4.0 Assembly (as it is now part of your references and physically placed in your BIN).

    Following is the EF Config before and after installing Sql Server Compact

    OLD Config:

    
        
              
                
              
            
            
              
            
          
    

    The new configuration is as below:

    
        
          
            
          
        
        
          
          
        
      
    

    and also it added the following section to describe new Factory

    
        
          
          
        
      
    

提交回复
热议问题