Save model contains a list of objects into a single row in the same table using 'SQLiteNetExtensions' NuGet package in xamarin forms.
Most Xamarin.forms developers prefer 'SQLite' for storing data into the local DB. The main limitation of the SQLite DB is it can't insert a model which contains any of the properties having a list data type. Here we can see how to save the model which contains any of the properties having list data type in the same table in a single row.
These are the steps to follow to save the data in the same table in a single row.
'SQLiteNetExtension' or 'SQLiteNetExtension.Async' NuGet package is required to install in project solution.
Add 'TextBlob' attribute to the model containing List data type property.
public class Person
{
public Person()
{
Id = Guid.NewGuid().ToString();
}
[PrimaryKey]
public string Id { get; set; }
public string Name { get; set; }
[TextBlob("AddressesBlobbed")]
public List<Address> Addresses { get; set; }
// serialized addresses
public string AddressesBlobbed { get; set; }
}
public class Address
{
public string StreetName { get; set; }
public string Number { get; set; }
public int PostalCode { get; set; }
public string Country { get; set; }
public DateTime CurrentDay { get; set; }
public double CityNo { get; set; }
public bool Values { get; set; }
}
Xamarin Training course is primarily designed for Beginner(s)/Professional(s) who want to learn how to develop native cross-platform apps with C# that run-on Android, iOS and Windows.
Learn how to add dark and light themes to your applications using Xamarin.Forms 4.7 and customize color styles in your app UI.
Xamarin,Forms 5 Preview is now available. The pre-release brings you more interactive controls with CarouselView, Paths, Gradients, and more.
Control exactly how your pages are displayed when navigating leveraging the PresentationMode built into Xamarin Today, I want to talk about a common feature of navigation where a new page pops up over the current page.
James and Matt will talk about multi-bindings and how using it in the right way will unleast the mysterious beast Inverter Converter.