エンティティ フレームワークのデータベース コンテキストから新しいデータを jTable に返そうとしています。このデータを並べ替えたいのですが、うまくいきません。変数をlinqクエリのorderbyステートメントに渡していますが、何をしてもソートされません。その文字列の値を入力すると機能するので、文字列変数をlinqクエリに追加できるかどうか疑問に思っていますか? ここで私が見た他のことから、それは一般的な問題のようです。
私はVS 2010、.net 4.0、MVC 3を使用しています。すでに追加してDynamic Linqを機能させようとし、System.Data.Entityを使用して追加しました。
[HttpPost]
public JsonResult WineList(string jtSorting = null, int ProducerID = 0)
{
try
{
jtSorting = "wine." + jtSorting.Replace("ASC", "ascending").Replace("DESC", "descending");
List<Wine> wines = db.Wines.Where(w => w.Active == true).Where(w => w.ProducerID == ProducerID).ToList();
//have to do this so we don't get circular references between producers and wines
var q = (from w in wines
let wine = new
{
WineID = w.WineID,
Producer = w.Producer.Name,
VarType = w.VarType.Name,
Vintage = w.Vintage.Name,
Name = w.ShortName,
App = w.App.Name
}
orderby(jtSorting)
select wine);
//var x = from w in q
// orderby jtSorting
// select w;
return Json(new { Result = "OK", Records = q });
}
catch (Exception ex)
{
return Json(new { Result = "ERROR", Message = ex.Message });
}
}
誰かが jtable を処理するより良い方法を持っている場合は、私もそれを受け入れます! ありがとう