Not insert children to database
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)
-
-
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
-
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 theFieldsBlobbed
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?
-
- changed status to closed
- Log in to comment
What do you mean by my FIELD table hasn't records? You are serializing the
Fields
property to theFieldsBlobbed
column inForm
table. You're not inserting any data intoField
table here.Also SQLite-Net Extensions requires that the relationship property is declared as
public
. If you cannot declare theFields
property aspublic
, try creating a wrapper property:If this doesn't work, try posting your read and write code to see what's happening.
Kind regards.