none
Getting an error trying to ExecuteFunction<..> on a simple stored procedure. (Includes steps to reproduce) Please help! RRS feed

  • Question

  • Hi folks,

    I've got an empty EF model which has one stored procedure imported using the ImportFunction wizard. I'm using POCO's so I've turned off the CustomTool that generates the entities, etc.

    When I try and ExecuteFunction<MyPoco>("myStoredProc", my params) i get an error: -

    System.InvalidOperationException: The value of EntityCommand.CommandText is not valid for a StoredProcedure command. The EntityCommand.CommandText value must be of the form 'ContainerName.FunctionImportName'.

    I have no idea how or where I can set this value?

    How to reproduce? sure :)

     

    1. Create an empty EF Model diagram.
    2. Delete/Turn Off the CustomTool, for the model.
    3. Import a stored procedure which returns a few files (eg. strings and ints).
    4. Because there's no entities or stuff auto-created, we need to create our own Context class which inherts from ObjectContext. Here's an example...

     

    public class SqlServerContext : ObjectContext
    {
        private readonly ILoggingService _loggingService;
    
        public SqlServerContext(EntityConnection entityConnection, ILoggingService loggingService)
            : base(entityConnection)
        {
            _loggingService = loggingService;
            _loggingService.Debug("Creating a new instance of a SqlServer Entity Framework Context.");
    
            ContextOptions.LazyLoadingEnabled = false;
        }
    
        public ObjectResult<Location> FindLocationsWithinABoundingBox(decimal upperLeftLongitude,
                                                                      decimal upperLeftLatitude,
                                                                      decimal lowerRightLongitude,
                                                                      decimal lowerRightLatitude)
        {
            return ExecuteFunction<Location>("FindLocationsWithinABoundingBox",
                                             new ObjectParameter("UpperLeftLatitude", upperLeftLongitude),
                                             new ObjectParameter("UpperLeftLongitude", upperLeftLatitude),
                                             new ObjectParameter("LowerRightLongitude", lowerRightLongitude),
                                             new ObjectParameter("LowerRightLatitude", lowerRightLatitude));
        }
    }
    
    
    

     

    And what is a Location object? it's a simple POCO class. Eg.

     

     

     

    public class Location
    {
        public int LocationId { get; set; }
        public byte LocationTypeId { get; set; }
        public string Name { get; set; }
        public string FullName { get; set; }
        public byte[] Boundary { get; set; }
    }
    

     

    And when i try and create an instance of my Context class, that works. But calling the Find method fails with that error...

     

     

    var context = new SqlServerContext(new EntityConnection("name=XWing_SqlServer_EF"), LoggingService); // <-- Works :)
    ObjectResult<Location> x = Context.FindLocationsWithinABoundingBox(upperLeftLongitude, upperLeftLongitude,
                                                                     lowerRightLongitude, lowerRightLatitude); // <-- Throws an error.
    
    
    
    

     

    Can someone explain what i've done wrong and/or missing from this?

    All I wish to do is call a stored procedure with the results going into my _own_ POCO object instances, please.

    PLEASE HELP! (I've already spent 2 days on this .. it's killing me and cost me $$$) :( :( :(

     


    -Pure Krome-
    Tuesday, August 3, 2010 8:36 AM

Answers

  • Hi,
    The ContainerName in the error only point out that you need to supply the name of the container (your ObjectContext) as prefix to the stored procedure name meaning that the code you wrote need to be changed into something like:
    ExecuteFunction<MyPoco>("SqlServerContext .myStoredProc", my params);

    I hope it will help you.


    Gil Fink
    • Marked as answer by Pure Krome Wednesday, August 4, 2010 1:43 AM
    Tuesday, August 3, 2010 11:40 AM

All replies

  • Hi,
    The ContainerName in the error only point out that you need to supply the name of the container (your ObjectContext) as prefix to the stored procedure name meaning that the code you wrote need to be changed into something like:
    ExecuteFunction<MyPoco>("SqlServerContext .myStoredProc", my params);

    I hope it will help you.


    Gil Fink
    • Marked as answer by Pure Krome Wednesday, August 4, 2010 1:43 AM
    Tuesday, August 3, 2010 11:40 AM
  • Thank you Gil. Perfect.

    For those people who are wanting to know what value to put into the ContainerName, it's the name of the ObjectContext ... which is found by double-clicking on the .edmx file and checking this (editable) value :-


    cheers!


    -Pure Krome-
    Wednesday, August 4, 2010 1:46 AM
  • If you don't want to include the container name before each procedurę name you can use another constructor of ObjectContext. Like this:

    public class SqlServerContext : ObjectContext
    {
        private readonly ILoggingService _loggingService;
    
        public SqlServerContext(EntityConnection entityConnection, ILoggingService loggingService)
            : base(entityConnection, "Entities") // the second constructor parameter is defaultContainerName - it will be used for all function calls
        {
            // your original code goes here ...
        }
    
        public ObjectResult<Location> FindLocationsWithinABoundingBox(decimal upperLeftLongitude,
                                                                      decimal upperLeftLatitude,
                                                                      decimal lowerRightLongitude,
                                                                      decimal lowerRightLatitude)
        {
                    // your original code goes here ...
        }
    }
    

    Wednesday, May 8, 2013 1:07 PM
  • hi

    tank you very very very Much 

    my problem was solved.

    Wednesday, October 16, 2019 6:17 AM