C# 如何从字典中找到价值<;int,IEnumerable<;结构>&燃气轮机;
我有一本字典,C# 如何从字典中找到价值<;int,IEnumerable<;结构>&燃气轮机;,c#,linq,dictionary,lambda,C#,Linq,Dictionary,Lambda,我有一本字典,SalaryFitnementDictionary,我想根据以下示例查询它(linq或lambda):其中employeedId=1和EarningDecretionId=145,并获取余额的值,EDBalance 我将如何实现这一点 var balance = salaryFitmentDictionary.Where... Dictionary<int, IEnumerable<SalaryFitmentInfoMonth>> salaryFitmen
SalaryFitnementDictionary
,我想根据以下示例查询它(linq或lambda):其中employeedId=1
和EarningDecretionId=145
,并获取余额的值,EDBalance
我将如何实现这一点
var balance = salaryFitmentDictionary.Where...
Dictionary<int, IEnumerable<SalaryFitmentInfoMonth>> salaryFitmentDictionary = new Dictionary<int, IEnumerable<SalaryFitmentInfoMonth>>();
employeeIdList.ToList().ForEach(employeedId =>
{
var perEmployeeFitments = from pf in _db.PayFitments.AsEnumerable()
join ed in _db.EarningDeductions.AsEnumerable()
on pf.EarningDeductionId equals ed.EarningDeductionId
where pf.EmployeeId == employeedId
select new SalaryFitmentInfoMonth
{
EDId = pf.EarningDeductionId,
EDAmount = pf.Amount,
EDBalance = pf.Balance.GetValueOrDefault(),
EDType = ed.EDType,
IsTaxable = ed.IsTaxable,
IsBenefit = ed.IsBenefit,
IsLoan = ed.IsLoan,
IsAdvance = ed.IsAdvance,
Limit = ed.TaxIfMoreThan.GetValueOrDefault()
};
salaryFitmentDictionary.Add(employeedId, perEmployeeFitments);
});
public struct SalaryFitmentInfoMonth
{
public int EDId { get; set; }
public decimal EDAmount { get; set; }
public decimal? EDBalance { get; set; }
public EarnDeduct EDType { get; set; }
public bool IsTaxable { get; set; }
public bool IsBenefit { get; set; }
public bool IsLoan { get; set; }
public bool IsAdvance { get; set; }
public decimal? Limit { get; set; }
}
var balance=salaryFitmentDictionary。其中。。。
Dictionary salaryFitmentDictionary=新字典();
employeeIdList.ToList().ForEach(employeedId=>
{
var PeremployeeFittents=来自_db.payFittents.AsEnumerable()中的pf
加入ed加入_db.EarningDeclements.AsEnumerable()
关于pf.earningdecreditionid等于ed.earningdecreditionid
其中pf.EmployeeId==EmployeeId
选择新的SalaryFitmentInfoMonth
{
EDId=pf.EarningDecreditionID,
EDAmount=pf.金额,
EDBalance=pf.Balance.GetValueOrDefault(),
EDType=ed.EDType,
IsTaxable=ed.IsTaxable,
IsBenefit=ed.IsBenefit,
IsLoan=ed.IsLoan,
IsAdvance=ed.IsAdvance,
Limit=ed.TaxIfMoreThan.getValuerDefault()
};
添加(EmployeeId,PeremployeeFittments);
});
public struct SalaryFitmentInfoMonth
{
公共int EDId{get;set;}
公共十进制数{get;set;}
公共十进制数?EDBalance{get;set;}
公共数据类型{get;set;}
公共布尔IsTaxable{get;set;}
公共bool IsBenefit{get;set;}
公共bool IsLoan{get;set;}
公共bool IsAdvance{get;set;}
公共十进制?限制{get;set;}
}
如果您希望有多个匹配项,则可以使用Enumerable.Where
而不是FirstOrDefault
如果您希望有多个匹配项,则可以使用Enumerable.Where
而不是FirstOrDefault
如果您希望有多个匹配项,则可以使用Enumerable.Where
而不是FirstOrDefault
如果需要多个匹配项,可以使用可枚举。其中
而不是FirstOrDefault
可以使用LINQ方法语法中的方法:
Int32 id = 1;
Int32 edId = 147;
var result = salaryFitmentDictionary.
Where((pair) => pair.Key == id ).
SelectMany((pair) =>
pair.Value.Where((perEmployeeFitment) => perEmployeeFitment.EDId == edId)).
Select(perEmployeeFitment => perEmployeeFitment.EDBalance).
Single();
或在查询语法中:
Int32 id = 1;
Int32 edId = 147;
var result = (from pair in salaryFitmentDictionary
from perEmployeeFitment in pair.Value
where pair.Key == id
where perEmployeeFitment.EDId == edId
select perEmployeeFitment.EDBalance).Single();
可以在LINQ方法语法中使用方法:
Int32 id = 1;
Int32 edId = 147;
var result = salaryFitmentDictionary.
Where((pair) => pair.Key == id ).
SelectMany((pair) =>
pair.Value.Where((perEmployeeFitment) => perEmployeeFitment.EDId == edId)).
Select(perEmployeeFitment => perEmployeeFitment.EDBalance).
Single();
或在查询语法中:
Int32 id = 1;
Int32 edId = 147;
var result = (from pair in salaryFitmentDictionary
from perEmployeeFitment in pair.Value
where pair.Key == id
where perEmployeeFitment.EDId == edId
select perEmployeeFitment.EDBalance).Single();
可以在LINQ方法语法中使用方法:
Int32 id = 1;
Int32 edId = 147;
var result = salaryFitmentDictionary.
Where((pair) => pair.Key == id ).
SelectMany((pair) =>
pair.Value.Where((perEmployeeFitment) => perEmployeeFitment.EDId == edId)).
Select(perEmployeeFitment => perEmployeeFitment.EDBalance).
Single();
或在查询语法中:
Int32 id = 1;
Int32 edId = 147;
var result = (from pair in salaryFitmentDictionary
from perEmployeeFitment in pair.Value
where pair.Key == id
where perEmployeeFitment.EDId == edId
select perEmployeeFitment.EDBalance).Single();
可以在LINQ方法语法中使用方法:
Int32 id = 1;
Int32 edId = 147;
var result = salaryFitmentDictionary.
Where((pair) => pair.Key == id ).
SelectMany((pair) =>
pair.Value.Where((perEmployeeFitment) => perEmployeeFitment.EDId == edId)).
Select(perEmployeeFitment => perEmployeeFitment.EDBalance).
Single();
或在查询语法中:
Int32 id = 1;
Int32 edId = 147;
var result = (from pair in salaryFitmentDictionary
from perEmployeeFitment in pair.Value
where pair.Key == id
where perEmployeeFitment.EDId == edId
select perEmployeeFitment.EDBalance).Single();
ToList().ForEach
ಠ_ಠ<代码>ToList().ForEachಠ_ಠ<代码>ToList().ForEachಠ_ಠ<代码>ToList().ForEachಠ_ಠ