gpt4 book ai didi

c# - 如何从 Entity Framework 上的匿名查询更改数据

转载 作者:行者123 更新时间:2023-11-30 16:43:49 25 4
gpt4 key购买 nike

我正在使用 Entity Framework 并且我有一个表用户和一个包含需要解密的数据的行,问题是当我进行查询以列出这些用户时我不能直接解密因为是匿名类型..

 var query = context.Users.Where(x => x.Id == id).Select(x => new
{
x.Id,
x.FirstName,
x.LastName,
x.UCP
});
response = Request.CreateResponse(HttpStatusCode.OK, query.ToList());

那么如何将数据从 UCP 更改为解密数据,我不是问如何解密而是如何更改!

最佳答案

var query = context.Users.Where(x => x.Id == id).Select(x => new
{
x.Id,
x.FirstName,
x.LastName,
x.UCP
})
.AsEnumerable()
.Select(x => new
{
x.Id,
x.FirstName,
x.LastName,
UCP = Decode(x.UCP)
});
response = Request.CreateResponse(HttpStatusCode.OK, query.ToList());

AsEnumerable 方法优于 ToList,它不创建集合

关于c# - 如何从 Entity Framework 上的匿名查询更改数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44275620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com