ページの1つに動的テーブルを持つMVCアプリケーションがあります。ユーザーは、テーブルに含まれる列の数、列の順序、および各フィールドのデータをどこから取得するかを定義します。
動的に保つためにいくつかの非常に悪いコードを書きましたが、今はもっと効率的にしたいと思っています。
私の問題は、実行時に IEnumerable に戻す必要がある列を定義する方法がわからないことです。私の主な問題は、列がいくつあるかわからないことです。
フィールドのテキストを取得するクラスへの参照があります。また、データを取得する必要がある正確なプロパティを含む各フィールドの順序の辞書もあります。
私のコードは次のようになります。
var docsRes3 = from d in docs
select new[]
{
for (int i=0; i<numOfCols; i++)
{
gen.getFieldText(d, res.FieldSourceDic[i]);
}
};
ここで:
docs = 特定のフィールドのみを取得したいリスト
res.FieldSourceDic = キーが列の順序で、値がプロパティである
辞書 gen.getFieldText = エンティティとプロパティを取得する関数値を返します
明らかに、うまくいきません。
私も試しました
StringBuilder fieldsSB = new StringBuilder();
for (int i = 0; i < numOfCols; i++)
{
string field = "d." + res.FieldSourceDic[i] + ".ToString()";
if (!string.IsNullOrEmpty(fieldsSB.ToString()))
{
fieldsSB.Append(",");
}
fieldsSB.Append(field);
}
var docsRes2 = from d in docs
select new[] { fieldsSB.ToString() };
それもうまくいきませんでした。
これまでのところ私にとってうまくいった唯一のことは次のとおりです。
List<string[]> docsRes = new List<string[]>();
foreach (NewOriginDocumentManagment d in docs)
{
string[] row = new string[numOfCols];
for (int i = 0; i < numOfCols; i++)
{
row[i] = gen.getFieldText(d, res.FieldSourceDic[i]);
}
docsRes.Add(row);
}
linq にフィールドのリストを渡す方法を教えてください。必要なデータが効率的に切り取られますか?
ありがとう、鍬私は私が必要なものについて明確でした....