locked
Exposing Stored procs- linq To Sql RRS feed

  • Question

  • Hi, I have a Linq to Sql class and I have added a stored proc to it so I could expose it in my data service in the following way, just like I would straightforwardly do if i were using Entity Data Model. But I am getting an error. Is it not possible to straightforwardly expose a Stored Proc in Linq To Sql to a Data service? Please advise
     [WebGet]
            public IQueryable<ToolQuestion> GetToolQuestions(int tooltype_id)
            {
                return CurrentDataSource.GetToolQuestions(tooltype_id);
             }
    Cannot implicitly convert type 'System.Data.Linq.ISingleResult<demoProject.GetToolQuestionsResult>' to 'System.Linq.IQueryable<demoProject.ToolQuestion>'. An explicit conversion exists (are you missing a cast?)
    Monday, May 2, 2011 6:41 PM

Answers

  • Finally, I found the answer. It was as simple as setting the return type of the stored proc in its properties the dbml file. And obviously had to type cast to AsQueryable like you suggested. Now its resolved.

     

    Thanks

    • Marked as answer by disuk Tuesday, May 3, 2011 6:36 PM
    Tuesday, May 3, 2011 6:36 PM

All replies

  • Have you tried calling AsQueryable<T> to convert the returned ISingleResult<T> (which implements IEnumerable<T>) to an IQueryable<T>, something like this?

    return CurrentDataSource.GetToolQuestions(tooltype_id).AsQueryable<ToolQuestion>();
    

    Glenn Gailey 

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, May 3, 2011 6:53 AM
  • Have you tried calling AsQueryable<T> to convert the returned ISingleResult<T> (which implements IEnumerable<T>) to an IQueryable<T>, something like this?

    return CurrentDataSource.GetToolQuestions(tooltype_id).AsQueryable<ToolQuestion>();
    

    Glenn Gailey 

     


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Ya i tried. It did not work. I get another error in addition to the one stated above 

    'System.Data.Linq.ISingleResult<demoProject.GetToolQuestionsResult>' does not contain a definition for 'AsQueryable' and the best extension method overload 'System.Linq.Queryable.AsQueryable<TElement>(System.Collections.Generic.IEnumerable<TElement>)' has some invalid arguments

     

     

    Tuesday, May 3, 2011 3:16 PM
  • Finally, I found the answer. It was as simple as setting the return type of the stored proc in its properties the dbml file. And obviously had to type cast to AsQueryable like you suggested. Now its resolved.

     

    Thanks

    • Marked as answer by disuk Tuesday, May 3, 2011 6:36 PM
    Tuesday, May 3, 2011 6:36 PM
  • But this is not a proper slution, each time you sp of the dbml you have to update or properties. Is there a way with out doing this.

    Tuesday, November 15, 2011 3:43 AM
  • On 11/14/2011 10:43 PM, Kodster wrote:
    > But this is not a proper slution, each time you sp of the dbml you have
    > to update or properties. Is there a way with out doing this.
    >
     
    Don't use a sproc?
     
    Tuesday, November 15, 2011 4:33 AM
  • Not very helpful, I need to use sp.
    Tuesday, November 15, 2011 7:45 AM
  • On 11/15/2011 2:45 AM, Kodster wrote:
    > Not very helpful, I need to use sp.
     
    You are not coming around anything concerning the model if you are
    making changes, which must be applied with an update to the model.
     
    There is no silver bullet.
     
    Tuesday, November 15, 2011 9:49 AM