Configure relationships in sqlite-net-pcl in MAUI

226 views Asked by At

I'm using sqlite-net-pcl and sqlite-net-extensions in .NET MAUI app and when I configure relationship between tables like this:

User can have 1:M countries

and calling SQLiteAsynConnection and inserting data like var users = new List<user> {new User()}...

UserCountry is not inserted

sqlite-net-pcl does not automaticly doing this ? I have to insert everything manually ?

_asyncDbConnection.Execute("PRAGMA foreign_keys = ON;");
User {

[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public List<UserCountry> Countries;
}
Country {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
}
UserCountry {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[ForeignKey(nameof(Country))]
public int CountryId {get; set;}
[ForeignKey(nameof(User))]
public int UserId {get; set;}
}
0

There are 0 answers