首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更新现有项目

更新现有项目
EN

Stack Overflow用户
提问于 2014-03-05 21:59:35
回答 1查看 106关注 0票数 0

在我的Windows 8 C#/XAML .NET 4.5应用程序中,我需要使用本地SQLite数据库。

因为我不是唯一一个做这个项目的人,所以数据库是由其他人创建的,我不喜欢在他的代码中编辑和/或搜索。

我需要找到一种方法来更新数据库中的现有元素,但我看不到任何更新的方法。我已经在谷歌上搜索过了,并找到了一种方法,我只是不确定我是否做得对(如果它能起作用)。

这是使用linq-2-sql?更新数据库中的项的正确方法吗?

示例:

代码语言:javascript
复制
MyDoctorModel doctor... //existing doctor, contains properties like Name, Phone, doctorId (which is corresponding to the Id of doctor in database)
dbContext               //existing object of database, custom made, contains table object + additional methods
//I'm linq-2-sql and linq rookie, so I'm not sure if it's normal or not

//dbContext.DOCTOR is object of the table in the database, contains
//columns like Id(integer),NAME(string) etc...

var dbDoctor = dbContext.DOCTOR.Where(e => e.Id == doctor.DoctorId).First();
dbDoctor.NAME = doctor.Name;
....//etc, updating values for the actual ones

dbContext.SubmitChanges(); //and submiting changes

这是更新表中现有项的正确方法吗?

我知道这可能很容易,这是一个基本的问题,但我找不到解释,这对我来说是令人满意的(足够简单,让我的笨脑袋明白)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-05 22:05:57

是的,这是正确的方法,您首先通过db context找到要更新的对象,然后更改它的一些属性,然后调用相同上下文的SubmitChanges

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22210272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档