如何根据两个参数 select 区分两个表中的数据?
How to select distinct data from two tables based on two parameters?
我有两个列表。
StateNotes - 州、CropYear、..其他属性
定价 - 州、CropYear、..其他属性
我想 select State 和 CropYear Pricings[=33= 中的每条记录] table 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();
这应该有效
var newStates = pricings.Where(x => !stateNotes.Any(p => p.State == x.State && p.CropYear == x.CropYear)).ToList();
你的功能是什么select 定价和 stateNotes 之间的区别
我有两个列表。 StateNotes - 州、CropYear、..其他属性 定价 - 州、CropYear、..其他属性
我想 select State 和 CropYear Pricings[=33= 中的每条记录] table 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();
这应该有效
var newStates = pricings.Where(x => !stateNotes.Any(p => p.State == x.State && p.CropYear == x.CropYear)).ToList();
你的功能是什么select 定价和 stateNotes 之间的区别