Is there a parent / child example out there somewhere? I’ve not seen one out there.
To be clear, I am not referring to a MasterDetailPage.
I am using Visual Studio 2017 Mac with a netstandard2.0 Xamarin Forms iOS / Android project solution. I’ve added sqlite-net-pcl version 1.4.118 NuGet; using XF version 3.1.0.x. I tried using the sqlite-net Extensions, but that crashes when I try to use OneToMany / ManyToOne.
Two models: a Player and Team (see below).
There can be many Players. A team can have 1 to many Players on it.
There are plenty of examples how to deal with the MVVM child (Player), so no examples need for that. I wanted a ContentPage that would allow the user to enter a new Team (name) at the top and a ListView / Grid of Players for that team via a Switch or Checkbox listed below the team name.
Models:
namespace Project.Models
{
[Table(“Player”)]
public class Player
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public string Position { get; set; }
}
}
namespace Project.Models
{
[Table(“Team”)]
public class Team
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public List Players { get; set; }
}
}
Note: the List Players will generate a runtime error. Note: I did think of a way to stuff the int list into a string and get it back out as a int list; however, I thought it important to get the concept across rather than it correctly working but a muddled.
That said, I’d think that this should be a (relatively speaking) common design pattern and I’d like to see an MVVM example of how to do this. I’ve searched the forum, but didn’t see any non-native XF example. I’ve also done a Bing search and didn’t find it an example there either.
Can anyone point me to some good links?