繁体   English   中英

c#firestore在visual studio项目中添加时间戳字段

[英]c# firestore add timestamp field in visual studio project

我使用库成功地将这些数据添加到我的 Visual Studio C# 应用程序的 Firestore:

Google.Cloud.Firestore

现在,我需要在时间戳中添加一个新字段,但如何清除它? 我还没有找到它的属性。 有什么建议吗?

谢谢

CollectionReference coll = database.Collection("reports");
            Dictionary<string, object> data1 = new Dictionary<string, object>()
            {
                {"fileId", fileId},
                {"fileName", fileName},
                {"type", type},
                {"userId", userId},
                {"url", urlReport },
                {"plantId", plantId },
            };
            coll.AddAsync(data1);

假设您使用的是Google.Cloud.Firestore库,我希望您能够使用FieldValue.ServerTimestamp

CollectionReference coll = database.Collection("reports");
Dictionary<string, object> data1 = new Dictionary<string, object>()
{
    {"fileId", fileId},
    {"fileName", fileName},
    {"type", type},
    {"userId", userId},
    {"url", urlReport },
    {"plantId", plantId },
    {"timestamp", FieldValue.ServerTimestamp}
};
await coll.AddAsync(data1);

请注意,该库也支持匿名类型,因此编写起来会更简单:

CollectionReference coll = database.Collection("reports");
var data1 = new { fileId, fileName, type, userId,
                  url = urlReport, plantId, timestamp = FieldValue.ServerTimestamp };
await coll.AddAsync(data1);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM