This question is locked. New answers and comments are not allowed.
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...
So I changed the method this way...
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
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
0
Accepted
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:
Hope that helps.
All the best,
Damyan Bogoev
the Telerik team
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
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
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
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
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
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
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
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
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!