Not insert children to database

Issue #67 closed
piotrek1231 created an issue

In my case models look like:

    public sealed class Form
    {
        [PrimaryKey]
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        [TextBlob("FieldsBlobbed")]
        internal List<Field> Fields { get; set; }
        public string FieldsBlobbed { get; set; } 
    }
    public sealed class Field
    {
        [PrimaryKey]
        public int Id { get; set; }
        public string Details { get; set; }
    }

I also try One-To-Many relations, but still my FIELD table hasn't records. I suppose that it can be connected with access modifier - in my case INTERNAL. Unfortunately, in PCL the List cannot be public.

Comments (4)

  1. Guillermo Gutiérrez

    What do you mean by my FIELD table hasn't records? You are serializing the Fields property to the FieldsBlobbed column in Form table. You're not inserting any data into Field table here.

    Also SQLite-Net Extensions requires that the relationship property is declared as public. If you cannot declare the Fields property as public, try creating a wrapper property:

    [TextBlob("FieldsBlobbed")]
    public List<Field> WrappedFields { get { return this.Fields; } set { this.Fields = value; } }
    

    If this doesn't work, try posting your read and write code to see what's happening.

    Kind regards.

  2. piotrek1231 reporter

    FIELD is the name of my table. Maybe this example will be simpler:

        public sealed class TaskResult
        {
            [PrimaryKey]
            public int Id { get; set; }
    
            [OneToMany(CascadeOperations = CascadeOperation.All)]
            **internal** List<FieldValue> FieldValues { get; set; } 
        }
    
        public sealed class FieldValue
        {
            [ForeignKey(typeof(Field))]
            public int FieldId { get; set; }
    
            public string Value { get; set; }
        }
    

    I have the object TaskResult and the list FieldValues has some objects. When InsertWithChildrenAsync is calling, it insert my object with type TaskResult, but not insert elements from list to table FieldValue

    Best regards

  3. Guillermo Gutiérrez

    These two samples are completely different. In the first one you were trying to serialize the property Fields into a string and save it in the FieldsBlobbed column. Now you are establishing a relationship between two different tables.

    Anyway, don't get stuck in that sentence. Did you read the rest of my response? The issue is that SQLite-Net Extensions requires that the relationship property is declared as public.

    Have you tried declaring the property public, or declaring a public wrapper for that property?

  4. Log in to comment