Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw store access APIs #624

Closed
divega opened this issue Sep 4, 2014 · 11 comments
Closed

Raw store access APIs #624

divega opened this issue Sep 4, 2014 · 11 comments

Comments

@divega
Copy link
Contributor

divega commented Sep 4, 2014

In previous versions of EF we had handy "raw SQL" methods such as SqlQuery and ExecuteSqlCommand that allowed to drop down to the underlying relational provider to execute SQL queries directly (i.e. bypassing the EF mapping) but still take advantage of some of the services provided by EF, e.g. connection management, transaction handling, object materialization and change tracking.

In EF7 since we support relational as well as non relational providers we should figure out how to extend this concept to specific providers through a consistent pattern, e.g. for Azure Table Storage it probably makes sense to provide access to the underlying objects from the .NET storage client library, while for relational stores being able to access the underlying connection and having something like SqlQuery and ExecuteSqlCommand defined as extension methods probably makes sense.

@rowanmiller rowanmiller modified the milestone: 1.0.0 Sep 5, 2014
@rowanmiller rowanmiller modified the milestones: Backlog, 7.0.0 Nov 26, 2014
@RickyLin
Copy link
Contributor

RickyLin commented Feb 4, 2015

hmm, any progress on this?

@rowanmiller
Copy link
Contributor

@RickyLin - We haven't started on this yet. It's a fairly isolated feature, so it will be something we work on a little later in the cycle.

@mikary
Copy link
Contributor

mikary commented Mar 20, 2015

We have added a FromSql method for relational DbSet<T>s that allows for materialization, change tracking, and additional querying off of a custom SQL statement. See #1845 and #1871 for more details and examples

@NicoJuicy
Copy link

In the meantime, you could probably use a extension method like this

public static int ExecuteSqlCommand(this RelationalDatabase database, string sql)
    {
        using (var connection = database.Connection)
        {
            using (var command = connection.DbConnection.CreateCommand())
            {
                command.CommandText = sql;
                return command.ExecuteNonQuery();
            }
        }
    }

@bricelam
Copy link
Contributor

@NicoJuicy Looks eerily familiar... 😉

@mikary
Copy link
Contributor

mikary commented Jun 25, 2015

@rowanmiller most of the functionality in this issue is covered by a combination of FromSql, #1862, and #1863

The only other facet is using a raw command on a non-relational store. Should we still keep this issue open as a reminder on the backlog, or is this something we can close?

@rowanmiller
Copy link
Contributor

@mikary yes I agree that those cover the remaining cases from this item

@rowanmiller
Copy link
Contributor

non-relational providers can do whatever makes sense for that particular store, so I don't think we need a general item.

@mikary mikary removed the 1 - Working label Jul 6, 2015
@mikary mikary removed their assignment Jul 6, 2015
@kant2002
Copy link

kant2002 commented Aug 5, 2015

Would be good to provide async version of #1863 (ExecuteSqlCommandAsync) as it was earlier. It's strange to have all API's Async but for this one only sync version.

@rowanmiller rowanmiller removed this from the Backlog milestone Aug 5, 2015
@rowanmiller
Copy link
Contributor

Clearing milestone so that we can discuss in triage. I think we have done almost everything here though we should discuss the async request from @kant2002

@divega
Copy link
Contributor Author

divega commented Aug 5, 2015

@rowanmiller agreed. The lack of async ExecuteSqlCommand is an oversight (thanks @kant2002!). I will just re-open #1863 and assign it to @mikary to track that. We can probably just close this one now.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants