如何在entityframework中交换两列数据? [英] How to exchange two column data in entityframework?

查看:51
本文介绍了如何在entityframework中交换两列数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何在Entityframework中交换两列数据?或者什么是LINQ查询/ lambda表达式来交换Entityframework中的两个列数据



就像我们在sql中有更新查询



UPDATE dbo.Employee

SET custom1 = custom2,custom2 = custom1



我尝试过:



i我没有得到如何开始......................

解决方案

这样的事情应该有效:

  //  检索要更改的记录: 
var employee = yourDbContent.Employees。< span class =code-sdkkeyword> Single (e = > e.Id == 42 < /跨度>);

// 交换数据:
var temp = employee.Custom1;
employee.Custom1 = employee.Custom2;
employee.Custom2 = temp;

// 更新数据库中的记录:
yourDbContext .SaveChanges();


Hi All,

how to exchange two column data in Entityframework ? or what will be LINQ query/lambda expression to exchange two column data in Entityframework

Like we have update query in sql

UPDATE dbo.Employee
SET custom1=custom2 , custom2=custom1

What I have tried:

i am not getting how to start ......................

解决方案

Something like this should work:

// Retrieve the record you want to change:
var employee = yourDbContent.Employees.Single(e => e.Id == 42);

// Swap the data:
var temp = employee.Custom1;
employee.Custom1 = employee.Custom2;
employee.Custom2 = temp;

// Update the record in the database:
yourDbContext.SaveChanges();


这篇关于如何在entityframework中交换两列数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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