Yes, and I suggest to make the collection a return value if you always replace it (which isn't the purpose of the observable collection):
public ObservableCollection<T> LoadStoreCollection<T>()
{
IList<T> queried = db.Query<T>();
return queried != null ? new ObservableCollection<T>(queried) : new ObservableCollection<T>();
}
For your first try with object: I have never used db4o but I think it uses the given type parameter (Load
or T
) in the Query
function to infer which table to query. Given object
yields an error as there is no table for object
. You need to specify a surrogate type or better - a generic type parameter - which will be bound the the actual type during execution. When called with T = Loan
, the db.Query
call can query the Loan
table as if you would have written db.Query<Loan>
in the first place.
As the collection was a parameter in the question, one could think you'd call the function multiple times for the same T
, but:
Always reinitialising the same observable collection variable with new
disables all benefits a observable collection can give, for example you'll never receive a collection changed event (because you listen on the replaced collection), you can't bind it to a control and if you register some other object to the event, you'll introduce a memory hole :)