MVC 应用程序的一些代码是使用 .NET 4.5 作为 VS 2012 中的框架构建的。我当前的系统迫使我在 VS 2010 上工作。我设法在我的 VS2010 中打开 VS2012 解决方案,但是事情是 VS2010 最多只支持 .NET 4。
代码中有一些函数使用仅适用于 .NET 4.5 的 dll 文件,例如 System.ComponentModel.DataAnnotations.Schema
。
那么,在 .NET 4 中是否有任何可用的替代函数/属性,我可以使用它们来执行与现在在 .NET 4.5 上相同的操作?
这是我当前使用 .NET 4.5 的代码:
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
}
如您所见,DatabaseGeneratedAttribute
在 System.ComponentModel.DataAnnotations.Schema
命名空间下可用,它是 .NET 4.5 的一部分。
关于可以在 .NET 4 中使用哪些相应的函数/属性来表示相同逻辑的任何建议?
注意:在上面给出的代码片段中,我在 Table
和 DatabaseGeneratedAttribute
上收到错误
The type or namespace name 'Table' could not be found (are you missing a using directive or an assembly reference?)
和
The type or namespace name 'DatabaseGeneratedAttributeAttribute' could not be found (are you missing a using directive or an assembly reference?)
分别。所以,我猜我只需要在 NET 4.0 中找到相应的类,事情就会水到渠成。非常感谢您的帮助。
最佳答案
从 .NET 4.5 更改为 4.0 后,我看到了同样的问题。根据this article .NET 4.0 的“ Entity Framework 程序集有一个特殊版本”包含 DataAnnotations
,否则它已被并入 .NET 4.5。
重新安装 Entity Framework 使 System.ComponentModel.DataAnnotations.Schema
再次工作。通过在程序包管理器控制台中键入以下内容重新安装:
Uninstall-Package EntityFramework
Install-Package EntityFramework
关于c# - .NET 4.0 替代 .NET 4.5 命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15328791/