O'Reilly logo

Fluent Entity Framework by Rebecca M. Riordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Executing SQL directly

The ObjectContext exposes a set of methods that allow you to execute SQL directly on your server and (depending on the method you choose and the SQL you execute) materialize them as entities in your context.

The ObjectContext.ExecuteStoreCommand() method can be used to execute any SQL that’s valid on your database server. It isn’t required, but it is considered best practice to use parameters rather than literal values:

Image

The DbContext also supports executing SQL directly, but it does it by way of the context’s Database property and the ExecuteSqlCommand() method. The syntax for specifying the SQL and any parameters is identical: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required