Tch*_*Dog 5 c# sql linq database
我正在尝试查询数据库并加入两个表.我从来没有使用过Join()这种方式,我在第二个Join()上遇到错误:
var adjustments = data.Inventory_ARCHIVEs
.Where(i => i.Location == comboBox3.Text &&
upcCodes.Contains(i.UPCCode) &&
(i.AVtime.Value.Date >= dateTimePicker1.Value.Date &&
i.AVtime.Value.Date <= dateTimePicker1.Value.AddDays(1).Date) &&
(i.BVtime.Value.Date >= dateTimePicker1.Value.Date &&
i.BVtime.Value.Date <= dateTimePicker1.Value.AddDays(1).Date))
.GroupBy(i => new { i.UPCCode })
.Select(i => new
{
ID = i.Max(x => x.ID),
i.Key.UPCCode
})
.Join(data.Inventory_ARCHIVEs, a => a.ID,
b => b.ID, (a, b) => new { a, b })
.Join(data.BQItems, x => new { x.a.UPCCode, x.b.Location },
y => new { y.UPC_Code, y.Location }, (x, y) => new
{
ID = x.a.ID,
UPCCode = x.a.UPCCode,
Date = x.b.BVtime.Value.Date,
Description = y.Description,
BVamount = x.b.BVamount,
AVamount = x.b.AVamount,
Difference = x.b.AVamount - x.b.BVamount,
AverageCost = x.b.AverageCost,
ExtCost = (x.b.AVamount - x.b.BVamount) * x.b.AverageCost
});
Run Code Online (Sandbox Code Playgroud)
x.a.UPCCode,x.b.Location,y.UPC_Code,和y.Location都是字符串.
这是错误:
方法'System.Linq.Enumerable.Join <TOuter,TInner,TKey,TResult>的类型参数(System.Collections.Generic.IEnumerable <TOuter>,System.Collections.Generic.IEnumerable <TInner>,System.Func <TOuter ,TKey>,System.Func <TInner,TKey>,System.Func <TOuter,TInner,TResult>)'无法从用法中推断出来.尝试显式指定类型参数.
如果我不通过"位置"列包含连接并只使用"UPCCode",它可以工作,但是当我按列添加第二个连接时,我收到错误
Jon*_*eet 19
我怀疑这是问题 - 至少有一个问题:
.Join(data.BQItems, x => new { x.a.UPCCode, x.b.Location },
y => new { y.UPC_Code, y.Location },
...)
Run Code Online (Sandbox Code Playgroud)
您正尝试使用两种不同的匿名类型作为键类型加入.他们有不同的属性 - 一个有UPCCode,另一个有UPC_Code.你可能想要:
.Join(data.BQItems, x => new { x.a.UPCCode, x.b.Location },
y => new { UPCCode = y.UPC_Code, y.Location },
...)
Run Code Online (Sandbox Code Playgroud)
或者只是更符合您的属性名称,以便您使用UPCCode或UPC_Code在任何地方使用,而不是混合使用.
| 归档时间: |
|
| 查看次数: |
5045 次 |
| 最近记录: |