簡體   English   中英

如何解決“ System.Data.Entity.Database.DefaultConnectionFactory”過時的問題?

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

在以下行中使用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)' 

怎么改呢?

從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/zh-cn/library/system.data.entity.database.defaultconnectionfactory(v=vs.113).aspx

另一個鏈接表明http://go.microsoft.com/fwlink/?LinkId=260883

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

您需要將繼承自System.Data.Entity.DbConfiguration的類添加到DbContext類所駐留的程序集中。

在該類的構造函數中,添加以下調用:SetDefaultConnectionFactory(new SqlCeConnectionFactory(“ System.Data.SqlServerCe.4.0”));;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM