1

Closed

GetGeneratedIdCommand in BasicMapping and Oracle

description

Hi, mattwar,
 
In GetGeneratedIdCommand function of BasicMapping:
protected virtual DeclarationCommand GetGeneratedIdCommand(MappingEntity entity, List<MemberInfo> members, Dictionary<MemberInfo, Expression> map)
    {
         .....
        var select = new SelectExpression(alias, columns, null, null); // no From
        return new DeclarationCommand(decls, select);
    }
The select express has no From, which is not allowed in Oracle. Oracle requires "select ... from dual".
 
Similarly, in GetSingletonSequence of QueryBinder, there is same issue, but this can be get around by setting language.AllowSubqueryInSelectWithoutFrom=false:
    private Expression GetSingletonSequence(Expression expr, string aggregator)
    {
        ....
        SelectExpression select = new SelectExpression(alias, new[] { new ColumnDeclaration("value", expr, colType) }, null, null);  // no From
        return new ProjectionExpression(select, new ColumnExpression(expr.Type, colType, alias, "value"), gator);
    }
 
I run all tests, and found three places:
BasicMapping.GetGenerateIdCommand
BasicMapping.GetInsertResult
QueryBinder.GetSingletonSequence
 
Now my simple solution is add below lines to end of SelectExpression constructor:
if (this.from == null)
{
            this.from = new TableExpression(new TableAlias(), null, "dual");
}
 
Is it possible to provide a way to set "dual" table somewhere to make the classes common?
I think it may be useful for other database besides Oracle.
 
Thanks
Wicky
Closed Apr 20, 2012 at 8:37 PM by mattwar
If you've made an Oracle provider you can override how the SQL is generated and insert a 'from dual' whenever a select without a from is generated.

comments