Support for Firestore Metadata fields (Id, CreateTimestamp, UpdateTimestamp, ReadTimestamp) in IFireStoreConverter<T>
See original GitHub issueIs your feature request related to a problem? Please describe. I’m using a custom converter to convert my type to/from a document (IDictionary<string,object>) to avoid decorating my types with attributes. (I want my types to be shared in other libraries where I can’t reference the Firestore lib.)
The custom converter works great, except I don’t think it exposes the 4 metadata properties you can get using attribute serialization:
- FirestoreDocumentId
- FirestoreDocumentCreateTimestamp
- FirestoreDocumentUpdateTimestamp
- FirestoreDocumentReadTimestamp
Describe the solution you’d like It would be awesome of these 4 properties could be passed through the IFirestoreConverter<T> class
Describe alternatives you’ve considered I don’t see any way to get these values using IFirestoreConverter<T> today.
Additional context I was exploring this scenario with the below types/converter:
using AutoMapper;
using Google.Cloud.Firestore;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
public static IMapper MapperInstance = new MapperConfiguration(cfg => { }).CreateMapper();
static async Task Main(string[] args)
{
// Set GOOGLE_APPLICATION_CREDENTIALS env variable here
FirestoreDbBuilder builder = new FirestoreDbBuilder();
builder.ConverterRegistry = new ConverterRegistry();
builder.ConverterRegistry.Add(new Converter());
builder.ProjectId = "<project id>";
FirestoreDb db = builder.Build();
await db.Collection("Testing").AddAsync(new MyFireStoreType
{
Prop1 = "foo",
Prop2 = 2
});
var result = await db.Collection("Testing").GetSnapshotAsync();
MyFireStoreType deserializedType = result[0].ConvertTo<MyFireStoreType>();
Console.WriteLine("Done");
}
}
public sealed class MyFireStoreType : FireStoreBaseObject
{
public string Prop1 { get; set; }
public int Prop2 { get; set; }
public bool? Prop3 { get; set; }
}
public abstract class FireStoreBaseObject
{
public string FirestoreDocumentId { get; set; }
public DateTimeOffset FirestoreDocumentCreateTimestamp { get; set; }
public DateTimeOffset FirestoreDocumentUpdateTimestamp { get; set; }
public DateTimeOffset FirestoreDocumentReadTimestamp { get; set; }
}
public class Converter : IFirestoreConverter<MyFireStoreType>
{
public MyFireStoreType FromFirestore(object value)
{
Dictionary<string, object> valueAsDict = (Dictionary<string, object>)value;
// Issue - no Id, CreateTimestamp, UpdateTimestamp, ReadTimestamp values available in the above dictionary
return Program.MapperInstance.Map<MyFireStoreType>(valueAsDict);
}
public object ToFirestore(MyFireStoreType value)
{
return Program.MapperInstance.Map<Dictionary<string, object>>(value);
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
@ryandle: I released 2.3.0 yesterday - thanks for working so collaboratively on this.
Okay, I’ve had an idea about how we should be able to make these available in an extensible, backwardly-compatible way. Basically you’d be able to configure additional properties that would be populated in the dictionary passed to
FromFirestore
. I’ll work on a PR today/tomorrow with that in…