无法使用我的实体框架v4 + POCO的存储过程:(

时间:2010-08-02 06:00:10

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

我有一个非常简单的实体框架项目,其中包含 POCO实体。我使用stored procedure导入了一个EF Wizard。 KEWL。

然后我创建了自己的EF Entity,然后我Add Function ImportStored Procedure映射到我的EF Entity

现在......我不确定如何将EF Entity映射到POCO。因此,我不断收到以下错误:

  

错误11007:实体类型'XXXXX'是   没有映射。

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

1 个答案:

答案 0 :(得分:6)

S'Ok。这就是我最终要做的事情。

使用POCO的

IE中。 .edmxCustom Tool被删除/没有自动生成的实体等

  1. 导入功能::手动导入存储过程。
  2. 在您的上下文课程中......

    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的默认方式)

    1. 创建自定义COMPLEX TYPE(也将用于映射存储过程)。
    2. 导入功能::手动导入存储过程。
    3. 将RETURN TYPE(导入的sp)映射到您自己创建的自定义COMPLEX TYPE。
    4. dat's it。

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

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