4

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.

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.

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?

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

Any suggestions on what the corresponding functions/attributes that could be used in .NET 4 to represent the same logic?

Note: In the code snippet given above, I get errors on Table and DatabaseGeneratedAttribute as

The type or namespace name 'Table' could not be found (are you missing a using directive or an assembly reference?)

and

The type or namespace name 'DatabaseGeneratedAttributeAttribute' could not be found (are you missing a using directive or an assembly reference?)

respectively. So, I am guessing that I just need to find the corresponding classes in NET 4.0 and things would fall into place. Your help is deeply appreciated.

4

4 回答 4

10

从 .NET 4.5 更改为 4.0 后,我看到了同样的问题。根据这篇文章“有一个特殊版本的实体框架程序集”,用于 .NET 4.0 DataAnnotations,其中包含 .NET 4.5。

重新安装实体框架System.ComponentModel.DataAnnotations.Schema再次工作。通过在包管理器控制台中键入以下内容重新安装:

Uninstall-Package EntityFramework
Install-Package EntityFramework
于 2014-08-26T10:38:03.360 回答
4

这篇文章中,作者声称能够使用System.ComponentModel.DataAnnotations.Schema在使用 VS2010 SP1 的 MVC4 应用程序中使用。

让我们知道这是否适合您。

于 2013-03-11T09:43:59.353 回答
1

Henrik 的解决方案也适用于相反的情况。我在从 .net 4.0 到 .net 4.5.1 以支持 MVC 5.2.3 时遇到问题。我得到了同样的错误。卸载并重新安装实体框架也解决了这种情况下的问题:

Uninstall-Package EntityFramework
Install-Package EntityFramework
于 2016-04-30T12:43:54.027 回答
0

包管理器控制台对我不起作用。我不得不去管理 Nuget 包来为我解决这个问题。我正在使用 VS.net 2013

于 2016-05-04T19:17:54.257 回答