LinqConnect and ORMBattle.NET

August 13th, 2010

ORMBattle.NET has recently updated their results of testing various .NET Framework ORMs and added LinqConnect to their lists. LinqConnect demonstrates one of the best results it their tests.

ORMBattle.NET is an open-source project for ORM comparison, supported by a development team from X-tensive.com. This project contains a set of tests for feature-oriented comparison, but it is more focused on the performance tests (CRUD operation performance, object materialization, etc.).

LinqConnect development team agrees with most of the tests. The results on the whole are reliable enough to consider them when choosing ORM framework.

We already are studying the situations where LinqConnect showed bad results and working on performance improvement.

Entity Framework Tips and Tricks, Part 2

July 30th, 2010

In this article we continue series of publications about non-trivial situations encountered by our users. Some of these situations are the restrictions of the used platforms, and some simply require a nonstandard approach to solving the problem.

We consider the following questions in this article:


1. How can I execute native SQL using Entity Framework?

Issue:

I don’t seem to be able to use CreateQuery. I have the following code:

using (Entities ent = new Entities())
{
        var results = ent.CreateQuery<PRODUCTS>("SELECT * FROM \"Products\"");

        foreach (var row in results)
        {
             Console.WriteLine("id: " + row.ID.ToString());
        }
}

This results in the error:

“The query syntax is not valid, near term ‘*’, line 1, column 11.”

What should I use to execute the native SQL?

Solution:

The CreateQuery method takes Entity SQL query, not SQL query.

To execute the SQL query you can use the ObjectContext.ExecuteStoreQuery method. Please note that it is available in the Entity Framework v4 only.

There is one more way to execute native SQL both in Entity Framework v1 and Entity Framework v4. You can use the StoreConnection property of the ObjectContext.Connection object. Here is an Oracle-specific sample:


using (OracleConnection connection
 = (entities.Connection as EntityConnection).StoreConnection as OracleConnection)
{
      OracleCommand command
        = new OracleCommand("SELECT * FROM \"Products\"", connection);

      connection.Open();
      OracleDataReader reader = command.ExecuteReader();

      //Materialize your query results here
}


2. How can I use Self-Tracking Entities (STE) in the Devart Entity Model?

Issue:

I am using EF 4.0 on top of your provider dotConnect for Oracle. I want to use Self-Tracking Entities. Can I rename edml file to the edmx file and use STE with this file?

Solution:

Devart model has structure similar to the one Microsoft model has. But there are some customizations. There should be no troubles with the extension changing (edml -> edmx).

There is one more approach to use STE with the .edml file:

  1. Go to the

    %Program Files%\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF.Utility.CS.ttinclude

  2. Change

    if (extension.Equals(".edmx", StringComparison.InvariantCultureIgnoreCase))
    

    to

    if(extension.Equals(".edmx", StringComparison.InvariantCultureIgnoreCase)
    ||
    extension.Equals(".edml", StringComparison.InvariantCultureIgnoreCase))
    

  3. Save the file

In case you are using VB.NET, you should perform these operations with the

%Program Files%\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF.Utility.VB.ttinclude file. Change the following line

If  (extension.Equals(".edmx", StringComparison.InvariantCultureIgnoreCase))

to

If (extension.Equals(".edmx", StringComparison.InvariantCultureIgnoreCase)
Or
extension.Equals(".edml", StringComparison.InvariantCultureIgnoreCase))

We plan to add support for the Self-Tracking Entities in one of the future builds.


3. How can I use Oracle stored procedures with a boolean parameter in Entity Framework?

Issue:

I am trying to execute a stored procedure with a PL/SQL BOOLEAN parameter in Entity Framework but always get a "ORA-06550: PLS-00306: wrong number or types of arguments in call to ‘EF_BOOLEAN_SP’".

Is it a bug, and is there any workaround for this situation?

Solution:

PL/SQL BOOLEAN parameters are not supported directly in Entity Framework, but there is a workaround for this case. Here are the steps to solve the problem:

  1. Add the procedure to Devart Entity model (you can perform all actions with ADO.NET Entity Data Model also, but these actions should be performed in XML using XML Editor)
  2. Change the type of the PL/SQL BOOLEAN parameters to bool
  3. Edit the CommandText for these procedure. Write a simple PL/SQL block calling the procedure. Don’t forget to pass the parameters, and convert the necessary parameters from NUMBER to PL/SQL BOOLEAN using the SYS.DIUTIL.INT_TO_BOOL function

    Here is a simple XML example:

    The text before changes:

    
    <Function Name=" EF_BOOLEAN_SP" IsComposable="false"
    BuiltIn="false" Aggregate="false" NiladicFunction="false" ParameterTypeSemantics="AllowImplicitConversion"
    Schema="TEST" StoreFunctionName="EF_BOOLEAN_SP">
              <Parameter Name="PK" Type="int64" Mode="In" />
              <Parameter Name="FLAG" Type="PL/SQL BOOLEAN" Mode="In" />
    </Function>
    
    

    The text after changes:

    
    <Function Name=" EF_BOOLEAN_SP" IsComposable="false"
    BuiltIn="false" Aggregate="false" NiladicFunction="false" ParameterTypeSemantics="AllowImplicitConversion">
          <CommandText>
             BEGIN
                 EF_BOOLEAN_SP(:PK, SYS.DIUTIL.INT_TO_BOOL(:FLAG));
             END;
          </CommandText>
          <Parameter Name="PK" Type="int64" Mode="In" />
          <Parameter Name="FLAG" Type="bool" Mode="In" />
    </Function>
    
    


4. How to work with UNION in Entity Framework?

Issue:

I have created the folowing union of two queries:

string productName  = "Spotlight on Britain's economy";
var query1 = context.Products.Where(t => t.Productname == productName);

productName = "Carroll Lewis. Alice'sventures in Wonderland ";
var query2 = context.Products.Where(t => t.Productname == productName);

var resultQuery = query1.Union(query2);
var ResultSets = resultQuery.ToList();

Because of some reason I get only one result – the book of Lewis Carroll. Is this a designed behaviour or bug?

Solution:

This is a designed behaviour. The reason of it is the deferred execution. The actual materialization of query1 and query2 occurs only in the following line:

var ResultSets = resultQuery.ToList();

Values of the parameters are passed in this moment also (productName points to the book of Lewis Carroll), and that’s why the results of query1 and query2 coincide.
The solution is to use different variables for parameters, or to materialize the query just after the parameter value is assigned.

In the first case, change your code in the following way:

string productName  = "Spotlight on Britain's economy";
var query1 = context.Products.Where(t => t.Productname == productName);

string productName2 = "Carroll Lewis. Alice'sventures in Wonderland ";
var query2 = context.Products.Where(t => t.Productname == productName2);

var resultQuery = query1.Union(query2);
var ResultSets = resultQuery.ToList();

In this case UNION statement is translated as a part of LINQ to Entities query.

In the second case both queries are materialized:

string productName  = "Spotlight on Britain's economy";
var query1 = context.Products.Where(t => t.Productname == productName);
query1.ToList();

productName = "Carroll Lewis. Alice'sventures in Wonderland ";
var query2 = context.Products.Where(t => t.Productname == productName);
query2.ToList();

var resultSet = query1.Union(query2);

In this case both lists are materialized before UNION is applied. That is why there is no need to materialize UNION itself, it is performed as a LINQ to Objects operation.


We hope this material will be useful for you. Please provide your feedbacks and suggestions in comments to article.

Entity Framework Tips and Tricks, Part 1

July 9th, 2010

This article will open a series of publications about non-trivial situations encountered by our users. Some of these situations are the restrictions of the used platforms, and some simply require a nonstandard approach to solving the problem.

Our first post consists of the following users’ questions concerning Entity Framework:

Read the rest of this entry »

Enumeration Support

May 17th, 2010


Introducing

We keep receiving requests about enumeration support in Entity Developer from our customers. That’s why we plan to implement this functionality in the second half of 2010.

In this article we describe the functionality concerning enumeration support we plan to add. It is only a draft and these features are a subject to change. It depends on the customer suggestions in many respects, so if you have any suggestions or requirements concerning this functionality, please write them as comments to this article or in any other way comfortable for you.
Read the rest of this entry »

dotConnect for Oracle Documentation Improved

April 9th, 2010

We read all your feedback reports to know how we may make our products better. The opinion of our users is important to us. Unfortunately, substantial part of user feedback reports rate our documentation as poor.

Last couple of months we have been working on dotConnect for Oracle documentation improvement. We have made improvements in two directions:

  1. Better table of contents, improving of current articles and writing new ones.
  2. Improving class reference (increasing number of samples, extending descriptions)

You can download the latest version of our documentation here. Older version of this documentation can be downloaded here for comparison.

We would like to know your opinion on the documentation changes, and which problems need more detailed coverage.

Dynamic Database Creation in Entity Framework

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.

Read the rest of this entry »

Entity Framework 4 Release Candidate supported!

March 31st, 2010

We have supported new functionality of Entity Framework 4 including Entity Framework v4 Release Candidate for dotConnect for Oracle, dotConnect for MySQL, dotConnect for PostgreSQL, and dotConnect for SQLite. In this article we consider basic new supported possibilities in comparison with Entity Framework v1. Take into account that the new features of Entity Framework v4 like Persistence Ignorance (POCO), Self-tracking entities, Code Only etc. which don’t require support of the provider writers aren’t described here.

Read the rest of this entry »

Entity Framework and IdeaBlade

March 26th, 2010

Our active user, Simon Kingaby, in his own blog has described experience of the web-based enterprise applications development by help of the following technologies: Devart dotConnect for Oracle, Entity Developer, Oracle 11 Database, Entity Framework, IdeaBlade DevForce, Microsoft Silverlight 3, Prism 2, and Unity.

You can view these articles by the following links:
IdeaBlade DevForce – Model Setup Walk-through – Background
IdeaBlade DevForce – Model Setup Walk-through – Step 1: The Entity Framework Project

Because of the increasing popularity of IdeaBlade among our users we plan to consider ways to improve its support. At first, we will implement a complete support of the custom attributes. Currently the serialization/deserialization of the conceptual model elements is provided only for part of them. Serialization of the conceptual model elements will be supported completely and EntityDeveloper will show and edit them in the next versions.

These changes will be useful for the users of the third-party tools which save additional information to the XML model as custom attributes. Also it will be useful for users who want to customize code generation – they can use attribute values in the code generation templates.

NHibernate and Oracle Database via dotConnect

March 24th, 2010

NHibernate is an ORM solution moved from Java to Microsoft .NET. It allows mapping application objects to relational database. NHibernate automatically generates SQL code for loading and saving objects. One of the approaches of NHibernate usage is entity mapping XML definition.

In this article we will talk about interaction of NHibernate with Oracle 11g. To establish connection to this database we will use the Devart dotConnect for Oracle provider built on ADO.NET technology to develop Oracle-based database applications.
Read the rest of this entry »

Entity Framework Canonical Functions

February 10th, 2010
Article was updated on 3/4/2010

This article can be useful for programmers who want to develop a cross-database applications and use the canonical functions.

Entity Framework Canonical Functions are a set of functions, which are supported by all Entity Framework providers. These canonical functions will be translated to the corresponding data source functionality for the provider.

The tables below contain information about these functions supported by the Devart products.
Functions supported by the following DBMS: MySQL, PostgreSQL, Oracle, SQLite, SQL Server 2005, and SQL
Server 2008 are marked with green.

Read the rest of this entry »