gpt4 book ai didi

c# - 您如何在连接中包含第一个表中的所有字段,以及剩余的一些字段?

转载 作者:行者123 更新时间:2023-11-30 17:00:34 24 4
gpt4 key购买 nike

鉴于以下情况:

var item = (from table1 in Entity.table1
join table2 in Entity.table2
on table1.ID equals table2.fkId
where table1.ID == TheID
select table1
)

我怎样才能返回 table1 中的所有字段,然后从 table2 中添加一些字段,而不必像这样再次显式定义所有列:

where table1.ID == TheID
select new
{
table1.field,
table1.field2,
etc, etc,etc,etc,
table2.field1

}

最佳答案

How can I return all the fields from table1, and then add a few from table2 without having to explicitly define all the columns

你不能。应指定匿名对象的所有属性。但是你可以从 table1 返回整个实例,从 table2 返回一些字段:

  select new
{
table1
table2.field1
}

然后第一个表中的所有属性都将通过 x.table1.field2 可用,您不会手动列出它们。

关于c# - 您如何在连接中包含第一个表中的所有字段,以及剩余的一些字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22070243/

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