gpt4 book ai didi

c# - Xamarin Firebase DeleteAsync

转载 作者:行者123 更新时间:2023-11-30 23:13:33 25 4
gpt4 key购买 nike

我在从我的 Xamarin Android 应用程序的 Firebase 数据库中删除项目时遇到问题。

我收到 400(错误请求)错误

删除方法:

private async void RemovePost(string ActivityID)
{
var firebase = new FirebaseClient(FirebaseURL);
await firebase.Child("posts").Child(ActivityID).DeleteAsync();

var intent = new Intent(mContext, typeof(MyProfileActivity));
mContext.StartActivity(intent);
}

型号:

public class Post
{
public string ActivityID { get; set; }

public string OwnerID { get; set; }

public string ActivityTitle { get; set; }

public string ActivitySport { get; set; }

public DateTime ActivityDate { get; set; }

public DateTime ActivityTime { get; set; }

public string ActivityTown { get; set; }

public string ActivityAddress { get; set; }

public string ActivityPhone { get; set; }

public string ActivityEmail { get; set; }

public string ActivityDetails { get; set; }
}

Firebase 数据库表: enter image description here

请注意我传递给 RemovePost 方法的事件 ID 是“0”

最佳答案

为什么一开始将记录保存到数据库时不将 ActivityId 作为键?

var post = new Post {
ActivityId = 0,
//...other properties populated
}

var record = await firebase
.Child("posts")
.Child(post.ActivityId)
.PostAsync(post));

var posts = await firebase
.Child("posts")
.OnceAsync<Post>();

foreach (var item in posts) {
Console.WriteLine($"{item.Key} post has id {item.Object.ActivityId}");
}

await firebase.Child("posts").Child(post.ActivityID).DeleteAsync();

这样在查询记录时你可以查询一个已知的键

关于c# - Xamarin Firebase DeleteAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43546796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com