Oracle

Using Entity Framework Spatials with Oracle Spatial and SharpMap

Thursday, November 29th, 2012

Spatials Overview

Entity Framework v5 introduces spatial data types support. They are represented as two new DbGeometry and DbGeography data types from System.Data.Entity.dll in .NET Framework 4.5.

Many our Oracle users use Oracle Spatial functionality in their projects. Before Entity Framework v5 there was no easy way to use Oracle Spatial with Entity Framework, though users of PostgreSQL, PostGIS, and SharpMap could use this cumbersome and limited workaround. This workaround was even harder to use with Oracle Spatial and was almost not used because of numerous limitations.

Now Entity Framework v5 changes the situation, and Devart dotConnect for Oracle provides the best possible support for Entity Framework Spatials and Oracle Spatial. It includes new versions of Devart.Data.Oracle.Entity.dll and Devart.Data.Oracle.Entity.Migrations.dll assemblies built for .NET Framework 4.5 (Entity Framework v5) and the new unsigned Devart.Data.Oracle.Entity.SharpMap.dll assembly for SharpMap library support.
(more…)

Using Oracle Full-Text Search in Entity Framework

Thursday, July 5th, 2012

Introduction

Oracle database supports an advanced functionality of full-text search (FTS) called Oracle Text, which is described comprehensively in the documentation:

We decided to meet the needs of our users willing to take advantage of the full-text search in Entity Framework and implemented the basic Oracle Text functionality in our Devart dotConnect for Oracle ADO.NET Entity Framework provider.
For working with Oracle Text specific functions in LINQ to Entities queries, the new OracleTextFunctions class is used, which is located in the Devart.Data.Oracle.Entity.dll assembly. It enables working with such Oracle Text functions as:

  • CONTAINS
  • CATSEARCH
  • MATCHES
  • SCORE
  • MATCH_SCORE

To call Oracle Text specific stored procedures of the CTX_DDL package, the OracleCtxDdlPackage class is used, which is located in the Devart.Data.Oracle.Entity.dll assembly.
To customize Code-First Migrations with the purpose of creating and deleting Oracle Text specific indexes, the CreateIndexConfiguration and DropIndexConfiguration classes are used, which are located in the Devart.Data.Oracle.Entity.Migrations.dll assembly.
This article deals with the following:

(more…)

Entity Framework Code-First Migrations support for Oracle, MySQL, PostgreSQL and SQLite

Monday, February 13th, 2012

ADO.NET EF providers Devart dotConnect for Oracle, dotConnect for MySQL, dotConnect for PostgreSQL, and dotConnect for SQLite implement support for Entity Framework 4.3 Beta 1 (Entity Framework Code-First Migrations). To use it in your applications, you need to download and install the corresponding Entity Framework NuGet package first. You can read about Entity Framework Code-First Migrations functionality in the corresponding MSDN articles.

Code-First Migrations Features

Entity Framework Code-First Migrations continues the development of Entity Framework Code-First functionality from Entity Framework 4.1 and Entity Framework 4.2, extending the functionality of dynamic database creating and deleting with the possibility of dynamic database schema modification (adding new columns/tables/foreign keys, creating and modifying existing database objects).

(more…)

Using Oracle Optimizer Hints in Entity Framework

Monday, 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

Monday, 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.

Set Identity and Computed Properties in Entity Framework Without Triggers

Tuesday, August 9th, 2011

This article deals with the following:

(more…)

Entity Framework Code-First support for Oracle, MySQL, PostgreSQL and SQLite

Tuesday, March 1st, 2011


April 2011 saw the release of a new version of Entity Framework 4.1; this blog article and samples of code contained in it have been correspondingly updated to match the new features that are now available.

The latest versions of Devart dotConnect for Oracle, dotConnect for MySQL, dotConnect for PostgreSQL, and dotConnect for SQLite contain the most recent version of Code-First (Code Only) support that was added in Entity Framework 4.1. One of the primary advantages of the Code-First approach is a higher level of abstraction from the database and the capability to develop applications using the domain-driven design (DDD) approach.

This article does not provide detailed examples of different aspects related to the use of the Code-First (Code Only) approach. For detailed information on the Code-First approach, see the series of publications on the ADO.NET team blog or MSDN documentation.

This article deals with the following:

(more…)

Using Oracle and MS SQL Server in Entity Framework applications simultaneously

Thursday, January 13th, 2011

Some of our users that are working with Entity Framework need to combine Oracle and Microsoft SQL Server in one application. Entity Framework is a powerful ORM with cross-database possibilities, so there is nothing extraordinary in this task.

However, there is a set of pitfalls and difficulties that are not obvious at first glance.

One of our users, Paul Reynolds, has made a series of posts based on his experience for multiple database support in EF:

Preparing for Multiple Databases
Database Caveats
SSDL Adjustments
Database Agnostic LINQ to Entities

Entity Framework: SQL Generation Enhancements for IN Clause

Thursday, December 9th, 2010


Introduction

Devart was the first company who shipped Entity Framework providers for Oracle, MySQL, PostgreSQL, SQLite. And now we remain the leader in supporting new versions and features of Entity Framework.

Continuing to improve support of Entity Framework v4 features, as it was described here, we have optimized generated SQL for our ADO.NET data providers – dotConnect for Oracle, dotConnect for MySQL, dotConnect for PostgreSQL, and dotConnect for SQLite.

SQL generation was significantly improved and simplified in Entity Framework 4. Most of these improvements can be used in third-party providers, but one aspect has been improved only for SqlClient. It is a conversion of IN expression in Entity SQL and Contains method for collections in LINQ to Entities.

New versions of our dotConnect implement this enhancement for both Entity Framework v4 and Entity Framework v1. Our EF v1 users can get optimized SQL for IN Entity SQL expressions, but LINQ to Entities doesn’t support Contains method for collections in EF v1.
(more…)

Dynamic Database Creation in Entity Framework

Wednesday, March 31st, 2010

Entity Framework 4 RC allows you to create and drop databases in run-time using SSDL for DDL generation. Now ObjectContext has CreateDatabase(), DropDatabase(), and CreateDatabaseScript() methods. They appeared in Entity Framework v4 CTP for Code Only and only for SQLClient initially but later they became available for other EF-providers.

In this article we describe implementation of these methods in Devart data providers. We are using dotConnect for Oracle as a data provider in the following examples. Northwind is used as a sample database.

(more…)


dotConnect Team Blog