0

我已经通过 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

字段 [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 “指定的架构无效。错误:(137,6):错误 0063:int 类型的属性不允许精确刻面。(137,6):错误 0063:不允许缩放刻面int 类型的属性。”

我尝试将 sproc 中的每个字段显式转换为 Varchar & int,通过 SqlQuery 函数而不是 sproc 显式执行查询(“SELECT TOP 10 ...”),从 sproc 中完全删除查询(即,离开sproc 的主体中没有任何内容),并且每次我都会得到完全相同的异常。任何帮助将不胜感激,谢谢。

4

1 回答 1

0

尝试打开您的 edmx 文件并删除您的 int 的精度属性

于 2013-03-05T12:09:40.060 回答