简体   繁体   中英

How to solve'System.Data.Entity.Database.DefaultConnectionFactory' is obsolete?

Using Asp.Net MVC at the following line:

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

I get error message:

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)' 

How to rewrite it?

Copied from msdn link

[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; }

Here is the link http://msdn.microsoft.com/en-us/library/system.data.entity.database.defaultconnectionfactory(v=vs.113).aspx

one more link it suggests http://go.microsoft.com/fwlink/?LinkId=260883

如果要使用配置文件设置DefaultConnectionFactory则可以遵循此http://msdn.microsoft.com/zh-cn/data/jj556606.aspx

You need to add a class inheriting from System.Data.Entity.DbConfiguration to the assembly where your DbContext class resides.

In the constructor of the class you add the call: SetDefaultConnectionFactory(new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM