locked
Dynamic SQl to LINQ....Ummm a little direction please RRS feed

  • Question

  •  

    OK, so what I am trying to do is dynamically populate some user documents. The physical path, name, and datasource(always a view) are set in a database table and I need most (if not all) the configuration for this to process to be maintainable in the db. My original thought was to do something like this:

     

    sp_MyDynamicProc

     

    @ViewName nvarchar(128),

    @Wherefield nvarchar(256),

    @Wherevalue nvarchar(256)

     

    AS

    BEGIN

    SET NOCOUNT ON

     

    DECLARE @statement nvarchar(2048)

    SET @statement = 'Select * from ' + @ViewName + ' where ' + @Wherefield + ' = ' + @Wherevalue

    EXEC sp_executesql @statement

     

     

    Very straight forward. I pass it a view name and the where criteria and it returns a dataset. No problem. HOWEVER, I can't define the result set as ISingleResult in my datacontext because I don't know what my result set will look like at design time. It could be five string fields or eleven int fields. Who knows. The point is I want to be able to use LINQ to do something like this. I am even will to capitulate and define all of the associated views in my datacontext (although I prefer not to if possible).....assuming I can get it to work. Ideas anyone? Thanks in advance.

    Wednesday, November 12, 2008 10:06 PM

Answers