Swa*_*yam 4 c# asp.net asp.net-mvc .net-4.0 .net-4.5
有一些MVC应用程序的代码是使用.NET 4.5作为VS 2012中的框架构建的.我当前的系统迫使我在VS 2010上工作.我设法在我的VS2010中打开VS2012解决方案,但问题是VS2010仅支持.NET 4.
例如,代码中有一些函数使用dll文件,这些函数仅适用于.NET 4.5 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; }
}
Run Code Online (Sandbox Code Playgroud)
如您所见DatabaseGeneratedAttribute,System.ComponentModel.DataAnnotations.Schema命名空间下可用,它是.NET 4.5的一部分.
有关.NET 4中可用于表示相同逻辑的相应功能/属性的建议吗?
注意:在上面给出的代码段中,我得到错误Table和DatabaseGeneratedAttributeas
找不到类型或命名空间名称"Table"(您是否缺少using指令或程序集引用?)
和
找不到类型或命名空间名称"DatabaseGeneratedAttributeAttribute"(您是否缺少using指令或程序集引用?)
分别.所以,我猜我只需要在.NET 4.0中找到相应的类,事情就会到位.非常感谢您的帮助.
从.NET 4.5更改为4.0后,我看到了同样的问题.根据这篇文章 "有一个特殊版本的Entity Framework程序集",包含.NET 4.0 DataAnnotations,它已经被整合到.NET 4.5中.
重新安装实体框架System.ComponentModel.DataAnnotations.Schema再次成功.在包管理器控制台中键入以下内容重新安装:
Uninstall-Package EntityFramework
Install-Package EntityFramework
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10666 次 |
| 最近记录: |