1

これは単純なはずで、私は信じられないほど密集していますが、それを理解するのに役立つ例を見つけることができません。パラメータを介して渡されるアイテムでtblAssetアイテムのリストをフィルタリングしたいと思います。assessmentIdパラメータ値は正常に取得できますが、クエリの記述方法がわかりません。

私のモデルは、モデル作成ウィザードを使用して既存のデータベースから構築されています。

助けてくれてありがとう!

public IEnumerable<tblAsset> GettblAssets()
{
  NameValueCollection nvc = HttpUtility.ParseQueryString(Request.RequestUri.Query);
  var assessmentId = nvc["aid"];

  //limit the assets by assessmentId somehow and return
}
4

1 に答える 1

0

データベースから返され.Whereたインスタンスでextensionメソッドを使用できます。IQueryable<tblAsset>

public IEnumerable<tblAsset> GettblAssets()
{
    NameValueCollection nvc = HttpUtility.ParseQueryString(Request.RequestUri.Query);
    var assessmentId = nvc["aid"];

    // TODO: you might need to adjust the property names of your model accordingly
    // Also if the assessmentId property is an integer on your model type
    // you will need to parse the value you read from the request to an integer
    // using the int.Parse method
    return db.tblAsset.Where(a => a.assessmentId == assessmentId);
}
于 2012-12-12T17:18:57.763 に答える