英文:
cut off all duplicate records by field leaving one
问题
我在数据库中有一张表,从中提取数据并在应用程序中显示。
大致而言,该表有两个字段:item_id 和 event field。
结果发现有一个事件是用户不想看到的。
现在有一个小困境。需要按原样显示所有内容,但不能在同一项上多次显示相同的事件。
有这样一个选项。但不适用,因为它只接受所有分组中的1条记录
var dummyVariable = result
.GroupBy(x => x.ActionCode)
.Select(group => group.First())
.ToList();
这是类:
public class GetBookingEventsRpcResponse
{
public long BookingEventId { get; set; }
public DateTimeOffset? EventDateTime { get; set; }
public BookingEventActionType ActionCode { get; set; }
}
目前的实际结果看起来像数据库截图。
我想避免在 (int)52 上重复显示 ActionCode。
相信解释清楚了。
英文:
I have a table in the database from which data is pulled out and displayed in the application.
Roughly speaking, the table has two fields: item_id and event field.
The event field is presented as a enum (the number in the table is recorded).
It turned out that there is an event that users do not want to see.
Now there is a little dilemma. It is necessary to display everything as it was, but not display the same event over this item more than once.
There is such an option. But it is not suitable, because it takes only 1 record of all grouped
var dummyVariable = result
.GroupBy(x => x.ActionCode)
.Select(group => group.First())
.ToList();
This is the class:
public class GetBookingEventsRpcResponse
{
public long BookingEventId { get; set; }
public DateTimeOffset? EventDateTime { get; set; }
public BookingEventActionType ActionCode { get; set; }
}
The actual result now looks like on screenshot of database.
I want to avoid dublication of ActionCode for (int)52.
Believe the explanation is clear.
答案1
得分: 2
这是您需要的翻译:
听起来你需要这个:
var dummyVariable =
result
.GroupBy(x => x.ActionCode)
.SelectMany(group => group.Key == 52 ? group.Take(1) : group)
.ToList();
英文:
It sounds to me that you need this:
var dummyVariable =
result
.GroupBy(x => x.ActionCode)
.SelectMany(group => group.Key == 52 ? group.Take(1) : group)
.ToList();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论