简体   繁体   English

.NET 4.0替代.NET 4.5命名空间

[英].NET 4.0 substitutes for .NET 4.5 namespaces

There is some code for an MVC application which was built using .NET 4.5 as a framework in VS 2012. My current system forces me to work on VS 2010. I managed to open the VS2012 solution in my VS2010, but the thing is that VS2010 supports only up to .NET 4. 有一些MVC应用程序的代码是使用.NET 4.5作为VS 2012中的框架构建的。我当前的系统迫使我在VS 2010上工作。我设法在我的VS2010中打开VS2012解决方案,但问题是VS2010仅支持.NET 4。

There are a few functions in the code which use dll files which are available only for .NET 4.5, for example System.ComponentModel.DataAnnotations.Schema . 代码中有一些函数使用仅适用于.NET 4.5的dll文件,例如System.ComponentModel.DataAnnotations.Schema

So, are there any substitute functions/attributes which are available in .NET 4, which I could use to do the same that is being done on .NET 4.5 right now? 那么,.NET 4中是否有可用的替代函数/属性,我现在可以使用它来完成与.NET 4.5相同的操作?

This is my current code using .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; }
    }

As you can see DatabaseGeneratedAttribute is available under the System.ComponentModel.DataAnnotations.Schema namespace, which is a part of .NET 4.5. 如您所见, DatabaseGeneratedAttributeSystem.ComponentModel.DataAnnotations.Schema命名空间下可用,该命名空间是.NET 4.5的一部分。

Any suggestions on what the corresponding functions/attributes that could be used in .NET 4 to represent the same logic? 有关.NET 4中可用于表示相同逻辑的相应功能/属性的建议吗?

Note: In the code snippet given above, I get errors on Table and DatabaseGeneratedAttribute as 注意:在上面给出的代码片段中,我在TableDatabaseGeneratedAttribute上得到错误

The type or namespace name 'Table' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或命名空间名称“Table”(您是否缺少using指令或程序集引用?)

and

The type or namespace name 'DatabaseGeneratedAttributeAttribute' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或命名空间名称“DatabaseGeneratedAttributeAttribute”(您是否缺少using指令或程序集引用?)

respectively. 分别。 So, I am guessing that I just need to find the corresponding classes in NET 4.0 and things would fall into place. 所以,我猜我只需要在.NET 4.0中找到相应的类,事情就会到位。 Your help is deeply appreciated. 非常感谢您的帮助。

I saw the same issue after changing from .NET 4.5 to 4.0. 从.NET 4.5更改为4.0后,我看到了同样的问题。 According to this article "there is a special version of the Entity Framework assembly" for .NET 4.0 containing DataAnnotations , which have otherwise been incorporated into .NET 4.5. 根据这篇文章 “有一个特殊版本的Entity Framework程序集”,用于包含DataAnnotations .NET 4.0,否则它已被合并到.NET 4.5中。

Reinstalling Entity Framework made System.ComponentModel.DataAnnotations.Schema work again. 重新安装Entity Framework使System.ComponentModel.DataAnnotations.Schema再次工作。 Reinstall by typing the following in Package Manager Console: 在包管理器控制台中键入以下内容重新安装:

Uninstall-Package EntityFramework
Install-Package EntityFramework

In this article , Author claims to be able to use System.ComponentModel.DataAnnotations.Schema in an MVC4 app using VS2010 SP1. 本文中 ,作者声称能够在使用VS2010 SP1的MVC4应用程序中使用System.ComponentModel.DataAnnotations.Schema

Let us know if this works out for you. 如果这对您有用,请告诉我们。

Henrik's solution also works for the opposite situation. Henrik的解决方案也适用于相反的情况。 I had an issue with going from .net 4.0 to .net 4.5.1 to support MVC 5.2.3. 我遇到了从.net 4.0到.net 4.5.1以支持MVC 5.2.3的问题。 I got the same errors. 我得到了同样的错误。 Uninstalling and Re-Installing Entity Framework solved the problem in this situation as well: 卸载和重新安装Entity Framework也解决了这种情况下的问题:

Uninstall-Package EntityFramework
Install-Package EntityFramework

The Package Manager Console didnt work for me. 包管理器控制台对我没用。 I had to go Manage Nuget packages to get this issue resolved for me. 我不得不去管理Nuget包来解决这个问题。 I am using VS.net 2013 我正在使用VS.net 2013

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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