Click here to Skip to main content
14,668,708 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello,

I'm struggling with a question about the implementation of the Model / Viewmodel in the MVVM pattern.

I have the folowing classes in my project

public class Client
{
    public int ID;
    public string Name;
}
public class Invoice
{
    public int ID;
    public Client MyClient;
}


The same structure is used in my SQLite database:
CREATE TABLE `Clients` (
	`ID`	integer NOT NULL PRIMARY KEY AUTOINCREMENT,
	`Name`	varchar
);
CREATE TABLE `Invoices` (
	`ID`		integer NOT NULL PRIMARY KEY AUTOINCREMENT,
	`Client_ID`	integer
);


I'm using sqlite-net to write to my database. But how should I map the Client object to the Client_ID column?
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi Wannnes,

Please consider the recommendations quoted at below link:
http://developer.nokia.com/community/discussion/showthread.php/248219-Implementing-Sqlite-Database-in-MVVM-Pattern-(Windows-Phone-Silverlight-8-1)[^]
as they said:
Quote:
I would recommend you install the SQLite-net package from NuGet in addition to the SQLite dll. This may make your life simpler. I know it makes it easier for me.
This way, you just create your tables based on your Models (or ViewModels) by calling dbConnection.CreateTable<{classname}>() .

Other useful links discussing similar scenario are:
http://blogs.u2u.be/diederik/post/2013/12/05/Using-SQLite-in-a-Windows-Store-MVVM-App.aspx[^]

http://msdn.microsoft.com/en-us/library/windows/apps/hh286405(v=vs.105).aspx[^]

Thanks.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100