4

这是什么意思?

用户代码未处理 System.MissingMethodException
HResult=-2146233069 消息=找不到方法:'System.Data.Entity.ModelConfiguration.Configuration.PrimitivePropertyConfiguration System.Data.Entity.ModelConfiguration.Configuration.StructuralTypeConfiguration1.Property(System.Linq.Expressions.Expression12<!0,!!0>>)'。Source=Att.Uds.DataLayerMappings StackTrace: att.Uds.DataLayerMappings.ItemTypeItemConfiguration..ctor() att.Uds.DataLayerMappings.UdsContext.OnModelCreating(DbModelBuilder modelBuilder) 在 c:\TFS\ATS-MSDev\UDS\Dev\ Code\Att.Uds.DataLayerMappings\UdsContext.cs:System.Data.Entity.DbContext.CallOnModelCreating(DbModelBuilder modelBuilder) 处 System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder() 处 System.Data.Entity.Internal 的第 163 行.LazyInternalContext.CreateModel(LazyInternalContext internalContext) 在 System.Data.Entity.Internal.RetryLazy2.GetValue(TInput 输入) InnerException:

此类发生错误:

namespace Contoso.Fabrikam.DataLayerMappings
{ 
  public abstract class NamedEntityConfiguration<TEntity> : EntityBaseConfiguration<TEntity> where TEntity : NamedEntity
  {
    public ConfigurationColumn NameColumn;
    protected new int LastOrdinalPosition
    {
      get
      {
        return (NameColumn.Ordinal);
      }
    }
    public NamedEntityConfiguration() <=== EXCEPTION HERE
    {
      NameColumn = new ConfigurationColumn() { Ordinal = base.LastOrdinalPosition+1, Name = "Name", IsRequired = true, Length = 128 };
      this.Property(t => t.Name)
        .HasColumnName(NameColumn.Name)
        .HasColumnOrder(NameColumn.Ordinal)
        .HasMaxLength(NameColumn.Length);
      if(NameColumn.IsRequired)
      {
        this.Property(t => t.Name).IsRequired();
      }
    }
  }
}

谢谢

4

3 回答 3

7

@Saber 他的回答有效的原因是,当您将项目升级到更高的 .NET 版本时,项目文件不会自动升级。例如,如果您从 .NET 4.0 升级到 .NET 4.5 并编辑项目文件,您可能会看到以下内容:

<Reference Include="EntityFramework">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.dll</HintPath>
    </Reference>
    <Reference Include="EntityFramework.SqlServer">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.SqlServer.dll</HintPath>
    </Reference>

您将不得不更改对net45而不是net40的引用。删除软件包时,这将产生相同的行为。

于 2015-04-21T20:17:37.287 回答
6

我遇到了同样的错误。它对我有用:

  1. 包管理器控制台中的卸载包 EntityFramework
  2. 从“packages”文件夹中删除 EntityFramework 文件夹
  3. 在包管理器控制台中安装包 EntityFramework
于 2014-09-21T13:16:10.703 回答
0

就我而言,我必须从此文件夹中删除 EntityFramework.dll:

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\EntityFramework

于 2015-04-07T15:02:07.397 回答