linq经常生成临时表,办法如下
1、得到单值
private List<string> FeeItems;
采用linq查询,例如
FeeItems = _context.表.Where(x => x.年 == CurrYear).OrderBy(s=>s.ItemId).Select(s => s.ItemId).ToList();
读值:
项目<InputSelect @bind-Value="SelectedItemID">
<option Value="" selected="selected">所有</option>
@foreach (var item in FeeItems)
{
<option Value="@item">@(GetItemName(@item))</option>
}
</InputSelect>
2、得到两个值
写一个类
public class CommonListItem
{
public string Id { get; set; }
public string Name { get; set; }
}
使用类
private List<CommonListItem>? depts;
采用linq查询,例如
depts = _context.表.Where(x => x.院区 == "66666" )
.Select(s => new CommonListItem
{
Id = s.DeptId,
Name = s.DeptName
}).OrderBy(s => s.Id).ToList();
读值:
科室<InputSelect @bind-Value="SelectedDeptID">
<option Value="" selected="selected">所有</option>
@foreach (var dept in depts)
{
<option Value="@dept.Id">@dept.Name</option>
}
</InputSelect>