0

我有一个存储数据并有 2 个外键的表“约会”。一个给customerId,一个给stylistId。我使用 ExecuteScalarAsync 创建了表,因此我可以自己创建外键,因为如果我使用 createTable 外键只是一些没有约束的数字(就像我可以为客户提供 5 的 ID,即使我没有客户编号 5)。

现在我想从我的表中取出一些约会,我需要客户 ID 来使用 .Where 函数显示数据并且一切正常,但是 customerId 和 stylistId 都是 0,即使在我的数据库中它们设置得很好。我使用 android 设备监视器来检查我的数据。

这是我的约会数据库

 public static async Task<Appointment> Get(int id)
        {
            await Init();
            try
            {
                var aux = await db_appointments.Table<Appointment>().Where(e => e.id == id).FirstOrDefaultAsync();
                return aux;
            }
            catch (Exception e)
            {
                Log.Error("ERROR getting the appointment from database\n" + e.Message + "\n" + e.StackTrace);
                return null;
            }
        }

这是我的数据库

在此处输入图像描述

如果我尝试在 UserId 上查询我的约会,我会得到一个空引用异常,但如果在 id 上查询我的 userId 和 stylistId 为 0

还有我的模特

        [PrimaryKey, AutoIncrement]
        public int id { get; set; }

        [ForeignKey(typeof(User)), OneToOne(CascadeOperations = CascadeOperation.All)]
        public int UserId { get; set; }

        [ForeignKey(typeof(Stylist)), OneToOne(CascadeOperations = CascadeOperation.All)]
        public int StylistId { get; set; }
        public string UserName { get; set; }
        public string StylistName { get; set; } 
        //public DateTime StartsAt { get; set; }
        //public HairType HairType { get; set; }
        //public Todo Todo { get; set; }
        public float Cost { get; set; }
        public int Duration { get; set; }
        public DateTime AppointmentCreated { get; set; }
        public DateTime AppointmentAnswered { get; set; }
        public Status Status { get; set; }
4

0 回答 0