Closed rezamohamed closed 6 months ago
The Documents
property is an IEnumerable<T>
for good reason. It defers the work needed to translate underlying native data objects to cross-platform .NET objects.
You can use the standard .NET extension method .ToList()
to transform the IEnumerable<T>
into a List<T>
. This is functionally equivalent to the code you've posted but more terse.
My issue isn't with the IEnumerable
var docs = snapshot.Documents.ToList();
My question was that I still have a List<IDocumentSnapshot>
, I am looking to get the List<Pokemon>
without having to iterate through and add each Pokemon to the list.
With the code that I was comparing to from the other plugin, yourmodels is aList<Pokemon>
var document = await CrossCloudFirestore.Current
.Instance
.Collection("yourcollection")
.Document("yourdocument")
.GetAsync();
var yourModel = document.ToObject<YourModel>();
Ah sorry. I understand now. The ToObjects()
and ToObject()
methods in the other plugin are just convenience methods for iterating over each snapshot just like you're doing. This plugin doesn't have equivalents right now, so yes you'll need to iterate yourself like: snapshot.Documents.Select(d => d.Data)
. It would be an easy enough thing to add, or create an extension method for.
Thanks @AdamEssenmacher that was my hunch, but i wanted to just make sure. The sample project here doesn't have a sample for firestore, so wanted to make sure I wasn't missing something
This is more a usage question Plugin.Firebase.Firestore.
I can retreieve an IEnumberable<IDocumentSnapshot> using
But to create a List is the only way to iterate through snapshot.documents like so?
I've used this plugin in Xamarin before, https://github.com/f-miyu/Plugin.CloudFirestore/tree/master?tab=readme-ov-file#get and it does a direct ToObject, so didn't know if I was missing something here is all.