//dotConnect Team’s Blog

Using Oracle Optimizer Hints in Entity Framework

January 23rd, 2012

With each new version of our Devart dotConnect for Oracle ADO.NET Entity Framework provider we pay special attention to improving its performance and configurability. It is pertinent to note some recent improvements: batch updates and flexible customization of Oracle Entity Framework provider behaviour. And now we are glad to present Oracle optimizer hints support in Entity Framework – a new feature for flexible tuning of SQL queries, generated by a user application.

Oracle Optimizer Hints

Oracle supports more than 60 different Oracle optimizer hints. You can see the complete list of Oracle optimizer hints and recommendations on their use in the Oracle Database documentation.

It is better to perform query optimization in external application, such as Devart dbForge Studio for Oracle, or any other tool for Oracle that you prefer. Queries, generated by Entity Framework, can be traced with dbMonitor and then copied and pasted to your SQL development application, where you can evaluate query performance, study execution plan, and choose optimizer hints to use.

Using Oracle Optimizer Hints as Oracle Function

Entity Framework provides not so many extensibility points for 3rd-party Entity Framework providers, so, to implement support for Oracle optimizer hints, we use database-specific functions feature in a non-standard way by adding the Devart.Data.Oracle.HINTS(string hints) function.

You can call this function directly in LINQ to Entities queries using the OracleFunctions class from the Devart.Data.Oracle.Entity assembly

var originalQuery = from emp in ctx.Exployees
                    ...
                    select emp;
var queryWithHints = originalQuery.Where(e =>
    OracleFunctions.Hints("INDEX(employees index1)"));
var result = queryWithHints.ToList();

or using query builder functionality of ObjectQuery (only when using ObjectContext, not DbContext).

var originalQuery = ctx.Exployees
                    .Where("Devart.Data.Oracle.HINTS('INDEX(employees index1)')")
                    ...
                    .Select(emp => emp);

Using Oracle Optimizer Hints as Extension Method

If you use ObjectContext, not DbContext, you can wrap this Devart.Data.Oracle.HINTS function and create an extension method, using the query builder feature of ObjectQuery.

public static class OracleExtensions {

    public static IQueryable<T> OracleHints<T>(
        this System.Data.Objects.ObjectQuery<T> source, string hints
    )
      where T : class {
      if (source == null)
        throw new ArgumentNullException("source");
      return source.Where("Devart.Data.Oracle.HINTS('" + hints + "')");
    }
}

Then you can use it in the following way:

var query = from emp in ctx.Exployees.OracleHints("FULL(employees) PARALLEL(employees, 5)")
            ...
            select emp;
var result = query.ToList();

Specifics and Limitations of Oracle Optimizer Hints in dotConnect for Oracle

We decided to always place hints after the first, upper-level SELECT keyword because structure of a generated SQL query does not always correspond to the structure of the LINQ to Entities query structure, and there is no unambiguous way to specify hints for a specific subquery.

var query = from emp in ctx.Exployees.OracleHints("FULL(employees) NOCACHE(employees)")
            ...
            select emp;
SELECT /*+ FULL(employees) NOCACHE(employees) */ last_name
  FROM employees;
...

If several hints are used, they are united in a single one.

var query = ctx.Employees
            ...
            select emp;
query = query.Where(e => OracleFunctions.Hints("FULL(employees)"));
query = query.Where(e => OracleFunctions.Hints("NOCACHE(employees)"));
SELECT /*+ FULL(employees) NOCACHE(employees) */ last_name
  FROM employees;

You cannot use string variables as OracleFunctions.Hints parameters, only string literals are allowed. For example, the following literal can be used:

var query = ctx.Employees.Where(e => OracleFunctions.Hints(
     "PARALLEL_INDEX(employees, index1, 3)"
));

and the following variable cannot:

string hints = "PARALLEL_INDEX(employees, index1, 3)";
var query = ctx.Employees.Where(e => OracleFunctions.Hints(hints);

Afterword

Thus, now dotConnect for Oracle Entity Framework provider has a new feature for flexible customization of SQL generation. Surely, Oracle optimizer hints is not a silver bullet and cannot solve all your problem, besides, one need some specific knowledge to use them. However, Oracle optimizer hints can be very useful in some cases, especially when changing database structure (creating/editing/deleting indexes, etc.) cannot be done for some reason. Oracle optimizer hints should be considered as one of the useful tools for developing applications using Entity Framework.

Workflow Foundation Support in dotConnect for Oracle

October 24th, 2011

We continue to extend the capabilities of dotConnect for Oracle with new features. Recently we have started to implement Workflow Foundation support features in dotConnect for Oracle. First we have implemented Oracle Workflow Instant Store support. This feature allows workflows to persist their state information in the Oracle database. dotConnect for Oracle provides the scripts for creating schema to store workflow instance state information in and the OracleWorkflowInstanceStore class that is used to persist workflow instance state information.

Currently only Enabling Persistence for Self-Hosted Workflows that use WorkflowApplication is supported. To use Oracle Workflow Instance Store you need Oracle server 9 or higher. To know how to enable Persistence for Self-Hosted Workflows read our documentation.

Recently we have added the OracleTrackingParticipant class to support Workflow Tracking. OracleTrackingParticipant class. This class allows you to subscribe to tracking records, reflecting key events during the workflow execution, and store these records to an Oracle database. dotConnect for Oracle provides the scripts for creating schema to store TrackingRecord object information. To know how to use the OracleTrackingParticipant read our documentation.

Visual Enhancements in Entity Developer 4.1

September 8th, 2011


As of version 4.1, Entity Developer supports several capabilities for visual presentation such as entity shape coloring, selection-driven highlighting and also contains sets of skins both for the application and its diagram.

This article deals with the following:

Read the rest of this entry »

Set Identity and Computed Properties in Entity Framework Without Triggers

August 9th, 2011

This article deals with the following:

Read the rest of this entry »

Explanation of Microsoft POCO and Self-Tracking Templates

July 13th, 2011

If a developer needs to introduce certain changes or adjust the behavior of Microsoft’s POCO or Self-Tracking templates of the EntityFramework model or to write a custom template from scratch based on Microsoft’s standard template, he or she will have to learn how these templates work.

When studying Microsoft’s POCO and Self-Tracking generation templates, I have come across significant difficulties in understanding the exact way these templates work, since they are far from being trivial. In this blog article, I shall endeavor to describe their basic functions, explain some points that might be so easy to understand, as well as the structure of the templates. Hopefully, this information will prove useful and time- and effort-saving to all developers who need to work with Microsoft’s generation templates for EntityFramework models.
Read the rest of this entry »

Using Entity Framework Power Tools CTP1 with Oracle, MySQL, PostgreSQL, and SQLite

June 13th, 2011


Released soon after Entity Framework 4.1, EF Power Tools CTP1 is intended to provide design-time support for the development that involves the use of the Entity Framework Code-First approach. EF Power Tools CTP1 can be downloaded from Visual Studio Gallery. Further in the article, you will find an explanation on how to use Entity Framework Power Tools with Devart dotConnect providers for Oracle, MySQL, PostgreSQL and SQLite, as well as information on Entity Developer that can be used as an alternative to Entity Framework Power Tools.

This article deals with the following:

Read the rest of this entry »

New Features of Entity Framework Support in dotConnect Providers

May 17th, 2011

In the new version of Devart dotConnect ADO.NET providers for Oracle, MySQL, PostgreSQL and SQLite we have significantly extended functional capabilities of Entity Framework. We maximally fulfilled requests of our users, including those received via our new UserVoice. Our users mainly requested new functional features, more flexibility in behavior and configuration as well as better performance.
Read the rest of this entry »

Entity Developer – EF Code First DbContext Template

May 17th, 2011

Note: To use the template “DbContext”, Entity Framework 4.1 and Entity Framework 4.0 must be installed on your computer.

April 2011 saw the release of a new version of Entity Framework 4.1 that supports fluent mapping and DbContext API. The latest version of Devart Entity Developer is extended with the DbContext template that enables the use of new features in EF v4.1. Initially, fluent mapping was intended to be used in the Code-First (Code Only) approach. However, thanks to our new template, fluent mapping can now be used not only in the Code-First approach, but in the Database-First/Model-First approaches as well.
Read the rest of this entry »

Working with Large Models and Oracle Autoincrement Fields in New Version of Entity Developer

March 24th, 2011

Starting from version 3.20, Entity Developer provides you with additional features to simplify working with models. Now you can split your model into diagrams to improve its readability. Entity Developer automatically generates a sequence and a trigger for autoincrement fields in Oracle when generating the database script from the model or when synchronizing the database with a model. We constantly work on improving Entity Developer and now we are focusing on performance increase and usability enhancement. The following enhancements have been added in the latest version:

Read the rest of this entry »

Provide your feedback on Entity Framework support in dotConnect data providers at UserVoice!

March 14th, 2011

Go to devart.uservoice.com and share your ideas about Entity Framework support in dotConnect data providers. There you may vote for features that are already in our roadmap, and they will have higher priority in our plans, or you may suggest your own features, and if they will get enough votes, we will include them to the roadmap. Your opinion helps us to make Entity Framework support in dotConnect data providers better and more useful for you.
LinqConnect at UserVoice

Read the rest of this entry »