linq to sql in update [英] linq to sql in update

查看:55
本文介绍了linq to sql in update的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

linq to sql in i有一个id(主键)作为参数,我想更新记录那些id并返回此id行表示整个值,表格中可用..



感谢高级...

linq to sql in i have one id (Primary key) as argument and i want to update record those id and return this id row means whole value which is available in table..

thanks in advanced...

推荐答案

var db = new MyDatabase();
var original = db.Users.Find(ObjUser.UserId);
if(original != null)
{
    original.Name = updatedUser.Name;
        original.Email = updatedUser.Email;
    db.SaveChanges();
}


你好keyur_raval597,



我更新了一个名为TL_Cateqory的表格返回更新的记录作为我的输出:

DataClasses1DataContext是我的dbml文件,我使用服务器资源管理器拖动了我的表。





Hi keyur_raval597,

I have updated a Table named TL_Cateqory and returned the updated record as my output:
DataClasses1DataContext is my dbml file in which i have dragged my table using server explorer.


DataClasses1DataContext obj1 = new DataClasses1DataContext();
Console.WriteLine(Update Single Record);
var sample = obj1.TL_Categories.Single(sd => sd.CategoryID == 6);
sample.CategoryName = "Hello";
obj1.SubmitChanges();
var output = obj1.TL_Categories.Where(c => c.CategoryID == 6);
Console.WriteLine(output);
foreach (var i in output)
{
 Console.WriteLine(i.CategoryID+i.CategoryName+i.AddedBy);
}
Console.ReadKey();


这篇关于linq to sql in update的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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