如何根据两个参数从两个表中选择不同的数据?

发布于 2025-01-31 12:05:10 字数 858 浏览 3 评论 0原文

我有两个列表。 史坦顿 - 状态,造物质,..其他属性 定价 - 状态,造物质,..其他属性

我想选择状态 chropyear pricings 表中的每个记录的 表中不存在于statenotes中。

示例:

statenotes

{State - Washington, CropYear - 2021 },
{State - Alabama, CropYear - 2022 },
{State - Nevada, CropYear - 2022 }

价格

{State - Washington, CropYear - 2021 },
{State - Alabama, CropYear - 2022 },
{State - Nevada, CropYear - 2021 } *<- this would be selected because there is no combination of Nevada-2021 in StateNotes*

我尝试的是:

var stateNotes = repository.AsQueryable<StateNotes>().ToList();
var newStates = pricings.Select(x => new { x.State, x.CropYear }).Except(stateNotes.Select(x => new { x.State, x.CropYear })).ToList();
           

I have two lists.
StateNotes - State, CropYear, ..Other properties
Pricings - State, CropYear, ..Other properties

I want to select State and CropYear of every record in Pricings table which is NOT present in StateNotes.

Example :

StateNotes

{State - Washington, CropYear - 2021 },
{State - Alabama, CropYear - 2022 },
{State - Nevada, CropYear - 2022 }

Pricings

{State - Washington, CropYear - 2021 },
{State - Alabama, CropYear - 2022 },
{State - Nevada, CropYear - 2021 } *<- this would be selected because there is no combination of Nevada-2021 in StateNotes*

What I tried :

var stateNotes = repository.AsQueryable<StateNotes>().ToList();
var newStates = pricings.Select(x => new { x.State, x.CropYear }).Except(stateNotes.Select(x => new { x.State, x.CropYear })).ToList();
           

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

別甾虛僞 2025-02-07 12:05:10

这应该起作用

var newStates = pricings.Where(x => !stateNotes.Any(p => p.State == x.State && p.CropYear == x.CropYear)).ToList();

的功能,您可以选择价格和史泰特人之间的区别

This should work

var newStates = pricings.Where(x => !stateNotes.Any(p => p.State == x.State && p.CropYear == x.CropYear)).ToList();

Whit that function you select the difference between pricings and stateNotes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文