EF4 CTP5: Raw SQL Queries for non-entity types RRS feed

  • Question

  • Had a question about leveraging CTP5's raw SQL support via SqlQuery for non entity types.  Is there any similar functionality to return a collection of System.Data.Common.DbDataRecord Objects?  I have not been able to locate documentation or examples where you have a database object to query and desire return more than a single primitive type.
    Friday, February 4, 2011 7:11 PM


  • Hi,

    There isn't native support for this on DbContext, the simplest option is probably to grab DbContext.Database.Connection and then use the .CreateCommand method and use the underlying ADO.NET components to run the query.

    You could also create a simple type that has properties that align with the result set you want and use DbContext.Database.SqlQuery to materialize them.


    Friday, February 4, 2011 10:06 PM