使用C#获取Cloud Firestore用户/电子邮件/(键:值)的数据
我试图通过使用电子邮件文本框,即TboxEmail。
DocumentReference docref = Data.Collection("users").Document(TboxEmail.Text);
DocumentSnapshot snap = await docref.GetSnapshotAsync();
我创建了一个Userinfo类,该类获取所有数据并仅选择所需的key:值。
using Google.Cloud.Firestore;
namespace FormApp
{
[FirestoreData]
class Userinfo
{
[FirestoreProperty]
public string email { get; set; }
[FirestoreProperty]
public bool status { get; set; }
[FirestoreProperty]
public string name { get; set; }
[FirestoreProperty]
public string address { get; set; }
[FirestoreProperty]
public int phone { get; set; }
}
}
编码。
bool s;
try
{
DocumentReference docref = Data.Collection("users").Document(TboxEmail.Text);
DocumentSnapshot snap = await docref.GetSnapshotAsync();
if (snap.Exists)
{
Userinfo userinfo = snap.ConvertTo<Userinfo>();
s = userinfo.status;
if (s)
{
this.Hide();
Dashboard home = new Dashboard(TboxEmail.Text);
home.ShowDialog();
return;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.StackTrace);
}
如果我在(Firestore)/ users(Collection)/ text(Document)中使用诸如test的普通文本,并在TboxEmail中进行测试,则代码运行良好。
问题是,当我使用电子邮件一样[email protected]在(公司的FireStore)/用户(系列)/电邮(文件),并把[email protected]在TboxEmail上面然后代码不能在数据转换用户信息。
来自ex.Message的异常是
Arithmetic operation resulted in an overflow
来自ex.StackTrace的异常是
很难猜测出确切的细节,但是异常提示整数存在问题。大多数电话号码都超出了int
数据类型的大小,所以我会去找。解决方案是将电话号码存储为字符串,以便您也可以表示国家/地区代码(例如+1),而不必担心整数精度。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句