C# 如何从列表中获取密钥<;对象>;在Xamarin的Firebase中。形式?
我正在用Xamarin.Forms编程,我也在使用FirebaseDatabase[dot]net Nuget 我有以下方法,连接到我的Firebase实时数据库,它发送一个列表C# 如何从列表中获取密钥<;对象>;在Xamarin的Firebase中。形式?,c#,firebase-realtime-database,xamarin.forms,C#,Firebase Realtime Database,Xamarin.forms,我正在用Xamarin.Forms编程,我也在使用FirebaseDatabase[dot]net Nuget 我有以下方法,连接到我的Firebase实时数据库,它发送一个列表 public static async Task<bool> PostDetallePedido(List<AgregarCarrito> carrito) { try { var result = await firebase
public static async Task<bool> PostDetallePedido(List<AgregarCarrito> carrito)
{
try
{
var result = await firebase
.Child("DetallePedidos")
.Child(Preferences.Get("idOrder", string.Empty))
.PostAsync(carrito);
result2 = result.Key;
var keyTable = new KeyClass()
{
keyU = result2,
orderId = Preferences.Get("idOrder", string.Empty)
};
await firebase
.Child("keyTable")
.Child(Preferences.Get("idOrder", string.Empty))
.PostAsync(keyTable);
return true;
}
catch (Exception e)
{
Debug.WriteLine($"Error:{e}");
return false;
}
}
编辑:
public static async Task<List<AgregarCarrito>> GetDetailByUser(int id)
{
try
{
var key = await GetKey(id);
var value = (await firebase
.Child("DetallePedidos")
.Child(Convert.ToString(id))
.Child(key.keyU)
.OnceAsync<AgregarCarrito>()).Select(item =>
new AgregarCarrito
{
orderId = item.Object.orderId,
ProductName = item.Object.ProductName,
CustomerId = item.Object.CustomerId,
Price = item.Object.Price,
TotalAmount = item.Object.TotalAmount,
ProductId = item.Object.ProductId,
Qty = item.Object.Qty,
imageUrl = item.Object.imageUrl,
Valor = item.Object.Valor
}).ToList();
return value;
}
catch (Exception e)
{
Debug.WriteLine($"Error:{e}");
return null;
}
}
publicstaticasync任务据我所知,到目前为止,您只想检索刚才插入的数据集
var postResult = await firebase
.Child("DetallePedidos")
.Child(Preferences.Get("idOrder", string.Empty))
.PostAsync(carrito);
// there is also a `GetAsync` method on your firebase database
var result = await firebase
.Child("DetallePedidos")
.Child(Preferences.Get("idOrder", string.Empty))
.GetAsync(postResult.YOURKEY); // i have no clue how to access the key in your case
据我目前所知,您只需要检索刚才插入的数据集
var postResult = await firebase
.Child("DetallePedidos")
.Child(Preferences.Get("idOrder", string.Empty))
.PostAsync(carrito);
// there is also a `GetAsync` method on your firebase database
var result = await firebase
.Child("DetallePedidos")
.Child(Preferences.Get("idOrder", string.Empty))
.GetAsync(postResult.YOURKEY); // i have no clue how to access the key in your case
你需要就你的问题提供更多的细节。不清楚你在问什么。@Daniel你说0和1是自动生成的?你想得到这把钥匙吗?你需要提供更多关于你的问题的细节。不清楚你在问什么。@Daniel你说0和1是自动生成的?要获取此密钥吗?我遵循了您提到的示例,您已经可以使用示例存储唯一id,我只能显示该唯一id中的元素,我添加了更多信息。我遵循了您提到的示例,您已经可以使用示例存储唯一id,我只能显示该唯一id中的元素,我添加了更多信息。