This is a migrated thread and some comments may be shown as answers.

AdoApi - problems with Translate<T>() within method

8 Answers 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Norbert
Top achievements
Rank 2
Norbert asked on 25 Nov 2011, 11:14 AM
Hello,

please tell me why this code doesn't work correctly?! It always returns null...
The datareader returns what I want but the method returns null...
public IEnumerable<T> AdoGetSql(string sql)
        {
           IEnumerable<T> results;
            using ( OACommand command = ctx.Connection.CreateCommand() )
            {
                command.CommandText = sql;
                using ( OADataReader reader = command.ExecuteReader() )
                {
                    results = ctx.Translate<T>(reader);
                }
            }
            return results;
        }

So I changed the method this way...
public IEnumerable<T> AdoGetSql(string sql)
        {
            List<T> results = new List<T>();
            using ( OACommand command = ctx.Connection.CreateCommand() )
            {
                command.CommandText = sql;
                using ( OADataReader reader = command.ExecuteReader() )
                {
                    results.AddRange(ctx.Translate<T>(reader));
                }
            }
            return results;
        }

It works now...but is it a good solution?

And how can I control the Transactionlevel within the AdoApi - I mentioned it is not allowed to use explicit transactions...
For example: How can I change the Isolation level only within my example method here?


Thank you in advance for help,
regards Norbert

8 Answers, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 28 Nov 2011, 04:49 PM
Hi Norbert,

Actually this is an expected behavior. The problem arises because the underlying data reader is closed when the IEnumerable collection, retrieved from the AdoGetSql method, is accessed. The collection is evaluated lazily which means and the reader should not be closed or disposed. 
You could force the materialization of the result by calling the ToList method:
public IEnumerable<T> AdoGetSql(string sql)
{
   IEnumerable<T> results;
    using ( OACommand command = ctx.Connection.CreateCommand() )
    {
        command.CommandText = sql;
        using ( OADataReader reader = command.ExecuteReader() )
        {
            results = ctx.Translate<T>(reader).ToList();
        }
    }
    return results;
}

Hope that helps.

All the best,
Damyan Bogoev
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Norbert
Top achievements
Rank 2
answered on 30 Nov 2011, 02:14 PM
Thank you, that solves the prolem.
But I've added a second question - how can I change the transaction level for one transaction? And is there a possibility to start a transaction explicitely?

Thank you in advance,
Norbert
0
Norbert
Top achievements
Rank 2
answered on 30 Nov 2011, 02:14 PM
Thank you, that solves the prolem.
But I've added a second question - how can I change the transaction level for one transaction? And is there a possibility to start a transaction explicitely?

Thank you in advance,
Norbert
0
Norbert
Top achievements
Rank 2
answered on 30 Nov 2011, 02:15 PM
Thank you, that solves the prolem.
But I've added a second question - how can I change the transaction level for one transaction? And is there a possibility to start a transaction explicitely?

Thank you in advance,
Norbert
0
Norbert
Top achievements
Rank 2
answered on 30 Nov 2011, 02:15 PM
Thank you, that solves the prolem.
But I've added a second question - how can I change the transaction level for one transaction? And is there a possibility to start a transaction explicitely?

Thank you in advance,
Norbert
0
Damyan Bogoev
Telerik team
answered on 30 Nov 2011, 06:12 PM
Hi Norbert,

I am afraid that currently you are unable to handle transactions in the ADO API explicitly. They are handled automatically by Telerik OpenAccess.

Greetings,
Damyan Bogoev
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
Norbert
Top achievements
Rank 2
answered on 01 Dec 2011, 11:54 AM
Thank you, that's pretty good but what if I want to change the isolation level for some transactions?
0
Damyan Bogoev
Telerik team
answered on 01 Dec 2011, 06:22 PM
Hello Norbert,

Currently the internal transaction handling includes the isolation level setup as well, this is by design.
I am sorry for the inconvenience caused.

Kind regards,
Damyan Bogoev
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Norbert
Top achievements
Rank 2
Answers by
Damyan Bogoev
Telerik team
Norbert
Top achievements
Rank 2
Share this question
or