更新Entityframe工作中表的特定列 [英] Update specific column of a table in Entityframe work

查看:111
本文介绍了更新Entityframe工作中表的特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i有一张桌子



Hi ,
i have a table with

ArticleID
Created_Date
CreatedBy
Modify_Date
Modify_By
IsActive
MemberID
ArticalTitle
ArticleTeaser
SEOFriendlyArticalTitle
ArticalDetails
CanDownloadAttachment
RoleTypeValue
ApprovedForPublish
ApprovedBy
EditorApprovalDate
TotalVisit
Ratting
TotalBooMarks
TotalDownload
TotalComments



这个字段



我用这个表更新这个表时




this fields

when i update this table with

db.CH_ArticleInfomation.Attach(ch_articleinfomation);


                db.ObjectStateManager.ChangeObjectState(ch_articleinfomation, EntityState.Modified);
                db.SaveChanges();



代码



所有字段都更新

但我只想更新




code

all fields are update
but I want to update only

Modify_Date
Modify_By
IsActive

ArticalTitle
ArticleTeaser
SEOFriendlyArticalTitle
ArticalDetails
CanDownloadAttachment
RoleTypeValue
ApprovedForPublish





我如何在Entity Framework中执行此操作。



how do i do this in Entity Framework.

推荐答案

请尝试如下。这只是一个示例。根据您的调整对象app。



步骤1:检索要更新的数据库对象。



ie

Please try is as below.This is just a sample.Adjust it according to your app.

Step 1 : Retrieve your db object which you want to update.

i.e.
var invoiceConfigobj = (from invoiceConfig in Catalog.InvoiceConfigurations
                                 where invoiceConfig.Provider.Id == providerId
                                 select invoiceConfig).SingleOrDefault();





第2步:之后更新字段你想要并保存回来。



ie



Step 2 : After that update the fields which you want and save it back.

i.e.

invoiceConfigobj.IsAllowInvoice = allowInvoice;
invoiceConfigobj.IsCustomerInvoice = customerInvoice;
invoiceConfigobj.Schedule = scheduleType;
invoiceConfigobj.ScheduleDate = scheduleDate;
Catalog.SaveChanges();


假设您要更新rating列的值。您必须编写以下代码

UPDATE TABLE_NAME SET RATING ='&Textbox1.text&'WHERE ID =&Textbox2.Text&
Suppose you want to update the value of rating column. You have to write the following code
UPDATE TABLE_NAME SET RATING='" & Textbox1.text & "' WHERE ID=" & Textbox2.Text & "


这篇关于更新Entityframe工作中表的特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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