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 #sqlite db #xamarin forms

Insert List Of Items Into Single Row In Xamarin Forms SQLite DB
2.65 GEEK