I am using DB4O
to store my objects. Please find below code to retrieve objects
from DBO4 DB.
public IList<T> GetList<T>()
{
IList<T> list = null;
using (IObjectContainer db = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), fullFilePath))
{
list = db.Query<T>(typeof(T));
}
return list;
}
The question is, I CAN NOT apply C# 'foreach' loop outside of using block. It gives me an error "Exception of type 'Db4objects.Db4o.Ext.DatabaseClosedException' was thrown." once I start traversing my List outside of Using block
I am able to apply C# 'foreach' loop inside using block, but I wants to use my generic list to another code layer. So, I must need my generic list object outside of using block.
Please give me solution for this.
Thanks in advance.
You have two possibilities:
ToList
for example), which iterates the IEnumerable<T>
and return that.