Search code examples
sqlentity-frameworkdbdatareader

How to get a DbDataReader object directly in Entity Framework?


According to MSDN (http://msdn.microsoft.com/en-us/library/dd487208.aspx), there is an object called DbDataReader that is created in the process of running a SQL query in Entity Framework.

Entity Framework "translates" the DbDataReader into a entity class.

How can I access the DbDataReader directly?


Solution

  • You can access the data reader it if you execute the query yourself:

    using (var command = context.Connection.CreateCommand())
    {
        command.CommandText = "SELECT ...3;
        using (var reader = command.ExecuteReader())
        {
            ...
        }
    }