5

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.

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

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

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

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

1 Answer 1

6

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

Using POCO's

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

  1. Import Function :: manually import the stored procedure.

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. Import Function :: manually import the stored procedure.
  3. Map the RETURN TYPE (of the imported sp) to the custom COMPLEX TYPE you've made.

dat's it.

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

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

3
  • I am facing the same problem. How did you map the return type to the custom complex type? Can you may be provide an example? Thanks in advance
    – sTodorov
    May 17, 2011 at 5:27
  • A bit old for a comment, but did you realise you've got: "UpperLeftLatitude" => upperLeftLongitude and vice versa in the code above? i.e. latitude maps to longitude?
    – hitch
    Oct 30, 2013 at 5:27
  • HAHAHA :) nice find :) nope :( i didn't
    – Pure.Krome
    Oct 30, 2013 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.