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上使用扩展方法: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 回答