如何解决“System.Data.Entity.Database.DefaultConnectionFactory”已过

本文关键字:Entity Data Database DefaultConnectionFactory 已过 System 何解决 解决 | 更新日期: 2023-09-27 18:31:54

在以下行使用 Asp.Net MVC:

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");

我收到错误消息:

Warning as Error: 'System.Data.Entity.Database.DefaultConnectionFactory' is obsolete: 'The default connection factory should be set in the config file or using the DbConfiguration class. (See http://go.microsoft.com/fwlink/?LinkId=260883)' 

如何重写?

如何解决“System.Data.Entity.Database.DefaultConnectionFactory”已过

从 msdn 链接复制

[ObsoleteAttribute("The default connection factory should be set in the config file or using the  DbConfiguration class. (See http://go.microsoft.com/fwlink/?LinkId=260883)")]
public static IDbConnectionFactory DefaultConnectionFactory { get; set; }

这是链接http://msdn.microsoft.com/en-us/library/system.data.entity.database.defaultconnectionfactory(v=vs.113).aspx

它建议的另一个链接http://go.microsoft.com/fwlink/?LinkId=260883

如果你想使用配置文件设置DefaultConnectionFactory那么你可以按照这个 http://msdn.microsoft.com/en-us/data/jj556606.aspx

您需要将从 System.Data.Entity.DbConfiguration 继承的类添加到 DbContext 类所在的程序集。

在类的构造函数中添加调用: SetDefaultConnectionFactory(new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"));