3 Replies - 1520 Views - Last Post: 10 August 2016 - 01:12 PM

#1 fearfulsc2  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 169
  • Joined: 25-May 16

trying to figure out a select using a stored procedure from sql

Posted 10 August 2016 - 11:27 AM

Hey everyone, I am trying to figure out how to print out a select statement from a stored procedure I created using the entity framework.

This is the stored procedure
create proc sp_selectpokemon(@Name NVARCHAR(100))
AS
  BEGIN
  BEGIN TRANSACTION
    BEGIN TRY
      SELECT Name FROM [Character].[Character]
      Where Name = @Name;
      COMMIT TRANSACTION
    END TRY
    
    BEGIN CATCH
      PRINT ERROR_MESSAGE();
      PRINT ERROR_SEVERITY();
      PRINT ERROR_NUMBER();
    END CATCH
  END;



This is the function for calling the stored procedure
  public void SelectSomePokemon(string name)
    {
      var data = db.sp_selectpokemon(name);
     
      Console.WriteLine(data);
    }



This is the function call for it passing the parameter
  public static void GetSomePokemonEF()
    {
      var data = new EFData();
      data.SelectSomePokemon("Mewtwo");
    }



And this is the output when I try to run it

System.Data.Entity.Core.Objects.ObjectResult`1[System.String]

Any idea what it is that I'm doing wrong here?

Is This A Good Question/Topic? 0
  • +

Replies To: trying to figure out a select using a stored procedure from sql

#2 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6375
  • View blog
  • Posts: 25,756
  • Joined: 12-December 12

Re: trying to figure out a select using a stored procedure from sql

Posted 10 August 2016 - 12:04 PM

Just based on a quick search I would first try adding FirstOrDefault() to db.sp_selectpokemon(name). Basically, ObjectResult is an Enumerable and this System.Data.Entity.Core.Objects.ObjectResult`1[System.String] I guess is its string representation.
Was This Post Helpful? 1
  • +
  • -

#3 fearfulsc2  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 169
  • Joined: 25-May 16

Re: trying to figure out a select using a stored procedure from sql

Posted 10 August 2016 - 12:07 PM

That did the trick. Thank you
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6375
  • View blog
  • Posts: 25,756
  • Joined: 12-December 12

Re: trying to figure out a select using a stored procedure from sql

Posted 10 August 2016 - 01:12 PM

You're welcome.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1