无法使用我的实体框架v4 + POCO的:(

时间:2022-09-30 02:05:45

I've got a very simple Entity Framework project with POCO Entities. I've got a single stored procedure which I have imported using the EF Wizard. Kewl.

我有一个非常简单的实体框架项目和POCO实体。我有一个使用EF向导导入的存储过程。酷。

I've then made my own EF Entity which I've then Add Function Import to map the Stored Procedure to my EF Entity.

然后我创建了自己的EF实体,然后添加函数导入,将存储过程映射到我的EF实体。

Now ... I'm not sure how to map my EF Entity to a POCO. As such, I keep getting the following error:

现在…我不知道如何将EF实体映射到POCO。因此,我不断得到以下错误:

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

错误11007:没有映射实体类型“XXXXX”。

I'm not sure how I can map this entity to a POCO. Can anyone help, please?

我不知道如何将这个实体映射到POCO。谁能帮助吗?

1 个解决方案

#1


6  

S'Ok. this is what I ended up doing.

'Ok。这就是我最后所做的。

Using POCO's

Ie. the .edmx, Custom Tool is removed / no auto-generated entities, etc.

Ie。.edmx,自定义工具被删除/没有自动生成实体,等等。

  1. Import Function :: manually import the stored procedure.
  2. 导入功能:手动导入存储过程。

In your context class ...

在你的上下文类中…

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));
    }
}

Using the Auto-Generated Entities, etc. (The default way EF is setup)

  1. Create a custom COMPLEX TYPE (which will be used to map the stored procedure, too).
  2. 创建自定义复杂类型(也将用于映射存储过程)。
  3. Import Function :: manually import the stored procedure.
  4. 导入功能:手动导入存储过程。
  5. Map the RETURN TYPE (of the imported sp) to the custom COMPLEX TYPE you've made.
  6. 将返回类型(导入的sp)映射到您所创建的自定义复杂类型。

dat's it.

dat的它。

Not sure if my POCO way is the best way to do things, but it .. well .. works :)

我不知道用我的方式做事是不是最好的方式,但是…嗯. .工作原理:)

And this is a related * question I asked about using this stored procedure in a services / IQueryable way ... :)

这是我问过的一个有关在服务/ IQueryable中使用这个存储过程的*的问题……:)

#1


6  

S'Ok. this is what I ended up doing.

'Ok。这就是我最后所做的。

Using POCO's

Ie. the .edmx, Custom Tool is removed / no auto-generated entities, etc.

Ie。.edmx,自定义工具被删除/没有自动生成实体,等等。

  1. Import Function :: manually import the stored procedure.
  2. 导入功能:手动导入存储过程。

In your context class ...

在你的上下文类中…

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));
    }
}

Using the Auto-Generated Entities, etc. (The default way EF is setup)

  1. Create a custom COMPLEX TYPE (which will be used to map the stored procedure, too).
  2. 创建自定义复杂类型(也将用于映射存储过程)。
  3. Import Function :: manually import the stored procedure.
  4. 导入功能:手动导入存储过程。
  5. Map the RETURN TYPE (of the imported sp) to the custom COMPLEX TYPE you've made.
  6. 将返回类型(导入的sp)映射到您所创建的自定义复杂类型。

dat's it.

dat的它。

Not sure if my POCO way is the best way to do things, but it .. well .. works :)

我不知道用我的方式做事是不是最好的方式,但是…嗯. .工作原理:)

And this is a related * question I asked about using this stored procedure in a services / IQueryable way ... :)

这是我问过的一个有关在服务/ IQueryable中使用这个存储过程的*的问题……:)