.net - 无法在我的 Entity Framework v4 + POCO :( 中使用存储过程

标签 .net entity-framework stored-procedures entity-framework-4 poco

我有一个非常简单的 Entity Framework 项目与 POCO实体 .我有一个 stored procedure我使用 EF Wizard 导入的.克尔。

然后我自己做了 EF Entity然后我 Add Function Import映射 Stored Procedure到我的 EF Entity .

现在......我不知道如何映射我的 EF EntityPOCO .因此,我不断收到以下错误:

Error 11007: Entity type 'XXXXX' is not mapped.



我不确定如何将此实体映射到 POCO .请问有人可以帮忙吗?

最佳答案

好的。这就是我最终要做的。

使用 POCO

IE。 .edmx , Custom Tool被删除/没有自动生成的实体等。

  • 导入函数::手动导入存储过程。

  • 在您的上下文类中...
    public class SqlServerContext : ObjectContext, IUnitOfWork
    {
        public SqlServerContext(EntityConnection entityConnection, 
                                ILoggingService loggingService)
            : base(entityConnection) { .... }
    
        public ObjectResult<Location> FindLocationsWithinABoundingBox(decimal upperLeftLongitude,
                                                                      decimal upperLeftLatitude,
                                                                      decimal lowerRightLongitude,
                                                                      decimal lowerRightLatitude)
        {
            return base.ExecuteFunction<Location>("FindLocationsWithinABoundingBox",
                                                  new ObjectParameter("UpperLeftLatitude", upperLeftLongitude),
                                                  new ObjectParameter("UpperLeftLongitude", upperLeftLatitude),
                                                  new ObjectParameter("LowerRightLongitude", lowerRightLongitude),
                                                  new ObjectParameter("LowerRightLatitude", lowerRightLatitude));
        }
    }
    

    使用自动生成的实体等(设置 EF 的默认方式)
  • 创建自定义 COMPLEX TYPE(也将用于映射存储过程)。
  • 导入函数::手动导入存储过程。
  • 将 RETURN TYPE(导入的 sp)映射到您创建的自定义 COMPLEX TYPE。

  • 就是这样。

    不确定我的 POCO 方式是否是最好的做事方式,但它.. 好.. 工作:)

    this is a related StackOverflow question I asked关于以服务/IQueryable 方式使用此存储过程... :)

    关于.net - 无法在我的 Entity Framework v4 + POCO :( 中使用存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3385372/

    相关文章:

    存储过程中的 MySQL 准备语句未按预期运行

    entity-framework - 如何将参数从 Entity Framework 传递给存储过程?

    mysql - 在经过净化的输入存储过程中使用准备好的语句有什么意义吗?

    c# - 文件流写入文件并读取 bfile

    c# - EF 更新不更新 GridView

    .net - 简单线程速成类?

    c# - 动态调用<T>对象类

    javascript - 将数组从 JavaScript 传递到 viewbag 并在 Controller 中使用它

    c# - ListView 中的换行符在 Vista/7 中有效,但在 XP 中无效

    c# - WPF 应用程序在添加或删除平板设备后停止响应触摸