【发布时间】:2019-12-27 12:32:12
【问题描述】:
我有一个名为 Asset 的表。它有很多列。我只想选择其中两个并单独使用它们。 这两列都是字符串。
Linq 查询:
public static List<string> GetAssetIdsWithNames()
{
using (var db = DbManager.Get())
{
var result = db.Assets.SelectMany(i=> new[] { i.AssetName, i.AssetId }).Distinct().ToList();
return result;
}
}
我想在哪里使用它们:
var assetList = AssetManager.GetAssetIdsWithNames();
//CURRENCYBOX IS A DROPDOWN
CurrencyBox.DataSource = assetList;
CurrencyBox.DataBind();
foreach (var item in assetList)
{
CurrencyBox.DataValueField = //asset id goes here
CurrencyBox.DataTextField =//asset name goes here
break;
}
【问题讨论】:
-
有什么问题?
-
@Izzy 我得到了列表
。我不能分别使用 AssetId 和 AssetName
标签: c# entity-framework linq webforms