SQlite Extensions One To One with list sub class

Joey Ireland 1 Reputation point
2021-03-05T13:27:18.19+00:00

Hi,

I have a class I have made with a sub class which is a list but when i use the OneToOne extension tag it is inserting it as null am I missing something?

my class:

public class RAMs
    {
        [PrimaryKey, AutoIncrement]
        public Int32 Id { get; set; }
        public String ProjectName { get; set; }

        [OneToOne]
        public List<Hazard> Hazards { get; set; }
    }

public class Hazard
    {
        public String HazardName { get; set; }
    }

and when i save into the local db i am using this snippet:

if (App.RamsDatabase.InsertRAMs(m))
            {
                await Navigation.PushAsync(new Edit(m.Id));
            }

public Boolean InsertRAMs(RAMs model)
        {
            lock (locker)
            {
                database.InsertWithChildren(model);

                return true;
            }
        }
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,323 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,273 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,951 Reputation points
    2021-03-08T02:24:47.877+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    when i use the OneToOne extension tag it is inserting it as null am I missing something

    The One-To-One extension is a one-way relationship. An example could be vehicle and registration certificate – each vehicle has one and only one registration certificate, and one registration certificate is associated with one and only one vehicle. It's not suitable for your needs.

    Try using One-to-many extension instead. One-to-many relationships are used in general for parent-children or whole-elements relations.

       public class RAMs  
       {  
           [PrimaryKey, AutoIncrement]  
           public Int32 Id { get; set; }  
           public String ProjectName { get; set; }  
         
           [OneToMany]  
           public List<Hazard> Hazards { get; set; }  
       }  
    

    You could google with the keyword as SSQLite-Net Extensions – one-to-one relationships and SQLite-Net Extensions – one-to-many relationships to check the related documentation.

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.