在MVVM中实现模型 [英] Implementation of model in MVVM

查看:122
本文介绍了在MVVM中实现模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在努力解决有关在MVVM模式中实现Model / Viewmodel的问题。



我的项目中有以下课程



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;
}





在我的SQLite数据库中使用相同的结构:



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
);





我正在使用sqlite -net写入我的数据库。但是我应该如何将Client对象映射到Client_ID列?



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

推荐答案

Hi Wannnes,



请考虑以下链接引用的建议:

http://developer.nokia.com/community/discussion/showthread.php/248219-Implementing-Sqlite-Database-in-MVVM-Pattern-(视窗-Phone-Silverlight-8-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:
引用:

除了SQLite dll之外,我建议你从NuGet安装SQLite-net包。这可能会让您的生活更简单。我知道它让我更容易。

这样,您只需通过调用 dbConnection.CreateTable< {classname}>()来创建基于Models(或ViewModels)的表。

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}>() .



讨论类似情况的其他有用链接是:

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 [ ^ ]



谢谢。


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.


这篇关于在MVVM中实现模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆