Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
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:
SQL
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

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900