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

Pur*_*ome 5 .net stored-procedures entity-framework poco entity-framework-4

我有一个非常简单的实体框架项目与POCO实体.我有一个stored procedure我用它导入的单曲EF Wizard.KEWL.

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

现在......我不知道如何将我映射EF Entity到一个POCO.因此,我不断收到以下错误:

错误11007:未映射实体类型"XXXXX".

我不知道如何将这个实体映射到一个POCO.有人可以帮忙吗?

Pur*_*ome 6

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

使用POCO

IE浏览器.的.edmx,Custom Tool被移除/无自动生成的实体等

  1. 导入函数::手动导入存储过程.

在你的上下文课......

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));
    }
}
Run Code Online (Sandbox Code Playgroud)

使用自动生成的实体等(EF设置的默认方式)

  1. 创建自定义COMPLEX TYPE(也将用于映射存储过程).
  2. 导入函数::手动导入存储过程.
  3. 将RETURN TYPE(导入的sp)映射到您自己创建的自定义COMPLEX TYPE.

dat就是它.

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

这是一个相关的StackOverflow问题,我问有关在服务/ IQueryable的方式使用该存储过程... :)