How to insert an ObservableCollection property to a local sqlite-net db?

I have a quick question about the sqlite-net library which can be found here :

The thing is I have no idea how collections, and custom objects will be inserted into the database, and how do I convert them back when querying, if needed.

Take this model for example:

[PrimaryKey, AutoIncrement]
public int Id { get; set; }
private string _name; // The name of the subject. i.e "Physics"
private ObservableCollection<Lesson> _lessons;


Preface: I've not used sqlite-net; rather, I spent some time simply reviewing the source code on the github link posted in the question.

From the first page on the sqlite-net github site, there are two bullet points that should help in some high level understanding:

  • Very simple methods for executing CRUD operations and queries safely (using parameters) and for retrieving the results of those query in a strongly typed fashion

In other words, sqlite-net will work well with non-complex models; will probably work best with flattened models.

  • Works with your data model without forcing you to change your classes. (Contains a small reflection-driven ORM layer.)

In other words, sqlite-net will transform/map the result set of the SQL query to your model; again, will probably work best with flattened models.

Looking at the primary source code of SQLite.cs, there is an InsertAll method and a few overloads that will insert a collection.

When querying for data, you should be able to use the Get<T> method and the Table<T> method and there is also an Query<T> method you could take a look at as well. Each should map the results to the type parameter.

Finally, take a look at the examples and tests for a more in-depth look at using the framework.

I've worked quite a bit with SQLite-net in the past few months (including this presentation yesterday)

how collections, and custom objects will be inserted into the database

I think the answer is they won't.

While it is a very capable database and ORM, SQLite-net is targeting lightweight mobile apps. Because of this lightweight focus, the classes used are generally very simple flattened objects like:

public class Course
    public int CourseId { get; set; }
    public string Name { get; set; }

public class Lesson
    public int LessonId { get; set; }
    public string Name { get; set; }
    public int CourseId { get; set; }

If you then need to Join these back together and to handle insertion and deletion of related objects, then that's down to you - the app developer - to handle. There's no auto-tracking of related objects like there is in a larger, more complicated ORM stack.

In practice, I've not found this a problem. I find SQLite-net very useful in my mobile apps.

Need Your Help

Weird string formatting after read() python

python string hex

I'm trying to read a file using Python

Restore mysql lost table

mysql backup database-restore

I accidentally deleted a table in my mysql database. After that I've restored this table from backup which is scheduled daily at 00:01. But there are lost data from 00:01 to 12:34. Is there a way to

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.