none
ISingleResult question. RRS feed

  • Question

  • Hi,

    i have a stored procedure to delete entries from a table that goes like this:

    -----------------------------
    set nocount on

    declare @description varchar(100)
    set @description = (select Description from Permissions  where VariableID = @VariableID)   

    if @description is not null
        select @description
    else
        begin   
            delete from SystemVariables where VariableID = @VariableID
            select ''
        end
    set nocount off
    return
    ---------------------

    I want to examine the string that i get from it so to inform the user if the deletion was successfull or not.
    I added it to the Linq-To-SQL designer and i see that it generated a function that returns an ISingleResult<SystemVariables_deleteResult>

    If i say something like this:

    string result = datacontext.SystemVariables_delete(entry.VariableID).ToString();

    i get back the type name for this interface and not the string that sp returns.

    So, how i can specify that this stored procedure returns a string so i will be able to get it back ?


    Thanks a lot for any help.
    Wednesday, September 2, 2009 10:51 AM

Answers

  • ISingleResult is actually an IEnumerable (despite the name). If you know it will always return only one row, it is safe to do this:

    var results = datacontext.SystemVariables_delete(entry.VariableID);
    
    string result = results.First().xxx;
    Where xxx is the appropriate property on the class "SystemVariables_deleteResult".


    More info about ISingleResult here: http://msdn.microsoft.com/en-us/library/bb534556.aspx

    • Marked as answer by King Kikapu Wednesday, September 2, 2009 11:43 AM
    Wednesday, September 2, 2009 11:15 AM

All replies

  • ISingleResult is actually an IEnumerable (despite the name). If you know it will always return only one row, it is safe to do this:

    var results = datacontext.SystemVariables_delete(entry.VariableID);
    
    string result = results.First().xxx;
    Where xxx is the appropriate property on the class "SystemVariables_deleteResult".


    More info about ISingleResult here: http://msdn.microsoft.com/en-us/library/bb534556.aspx

    • Marked as answer by King Kikapu Wednesday, September 2, 2009 11:43 AM
    Wednesday, September 2, 2009 11:15 AM
  • ISingleResult is actually an IEnumerable (despite the name). If you know it will always return only one row, it is safe to do this:

    var results = datacontext.SystemVariables_delete(entry.VariableID);
    
    string
     result = results.First().xxx;
    
    Where xxx is the appropriate property on the class "SystemVariables_deleteResult".


    More info about ISingleResult here: http://msdn.microsoft.com/en-us/library/bb534556.aspx


    Hi and thanks for the (ultra fast) reply!

    So, i code it like you said:

                    var results = db.SystemVariables_delete(entry.VariableID);
                    string result = results.First().Column1;

    but Column1 always returns null and i cannot figure out why...

    I changed the sp to contain only this (and nothing else):

                    select 'something' as col

    and it stills returns me null...I am very frustrated, i only want to get the string "something" back...

    Any ideas ?

    Thanks again for the help!


    Wednesday, September 2, 2009 11:30 AM
  • I figured out what the problem was...

    The Linq-to-SQL designer seemed to be unable to re-fetch correctly the stored procedure after the change i made and so "Column1" was it's guess where it should have given me the name "col", as i was specified in the sp.

    This was going on even if i deleted and re-added the sp to the designer and doing several "refresh" on it (in database explorer).

    I shutdown VS and restarted it and do the same thing again and this time it is worked.

    I can now get the results i need but the whole designer-story was scaring enough...
    Wednesday, September 2, 2009 11:48 AM