EF Code First MetadataException

时间:2012-10-17 16:14:31

标签: c# .net sql-server entity-framework

我已经通过NuGet将EF v5安装到VS 2010项目中。这是代码:

public class HeliosCpDataContext : DbContext
{
    public HeliosCpDataContext() : base(Properties.Settings.Default.cn_HeliosCpNtAuth) {}
    public IEnumerable<Test> GetTests()
    {
            return this.Database.SqlQuery<Test>("EXEC App.Test");
    }
}

   public class Test
    {
       public string OrderNumber { get; set; }
       public int OrderId {get;set;}
    }

   CREATE PROC [dbo].[Test]
   AS 
    SET NOCOUNT ON


SELECT TOP 10 OrderNumber, OrderId
FROM dbo.Orders o

Field [OrderNumber]是Varchar(20),[OrderId]是INT

这是app.config:

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="HeliosCp.Data.Properties.Settings.cn_HeliosCpNtAuth"
      connectionString="Data Source=DCXVRSQ471;Initial Catalog=SCPT_HeliosCp;Integrated Security=True;MultipleActiveResultSets=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

当我尝试执行时:

  var context = new HeliosCp.Data.HeliosCpDataContext();
  var test = context.GetTests().FirstOrDefault();

我收到MetadataException“指定的Schema无效。错误: (137,6):错误0063:int类型的属性不允许使用精度构面。 (137,6):错误0063:对于int类型的属性,不允许使用缩放方面。“

我已经尝试将sproc中的每个字段显式地转换为Varchar&amp; int,通过SqlQuery函数而不是sproc显式执行查询(“SELECT TOP 10 ...”),完全从sproc中删除查询(即,在sproc的主体中不留任何内容) ),每次都得到完全相同的异常。非常感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

尝试打开edmx文件并删除int

的precision属性
相关问题