Durandal Web アプリケーションでbreezejs を使用しています。
請求書とその背後にある行を取得するためのコードは次のとおりです。
var getInvoiceById = function (invoiceId, invoiceObservable, forceRemote) {
// Input: invoiceId: the id of the invoice to retrieve
// Input: forceRemote: boolean to force the fetch from server
// Output: invoiceObservable: an observable filled with the invoice
if (forceRemote)
queryCacheInvoice = {};
var query = entityQuery.from('Invoices')
.where('id', '==', invoiceId)
.expand("Client, Client.Contacts, Lines")
.orderBy('Lines.Number');
var isInCache = queryCacheInvoice[invoiceId];
if (isInCache && !forceRemote) {
query = query.using(breeze.FetchStrategy.FromLocalCache);
} else {
queryCacheInvoice[invoiceId] = true;
query = query.using(breeze.FetchStrategy.FromServer);
}
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
function querySucceeded(data) {
invoiceObservable(data.results[0]);
}
};
請求書のモデルは次のとおりです。
public class Invoice
{
[Key]
public int Id { get; set; }
public string Number { get; set; }
public DateTime? Date { get; set; }
public int? ClientId { get; set; }
public string Comment { get; set; }
public double? TotalExclVAT { get; set; }
public double? TotalInclVAT { get; set; }
public double? TotalVAT { get; set; }
public bool? WithoutVAT { get; set; }
public virtual List<InvoiceLine> Lines { get; set; }
public virtual Client Client { get; set; }
}
請求書ごとに、多くの請求書明細があることに注意してください。
public virtual List<InvoiceLine> Lines { get; set; }
InvoiceLine のモデルは次のとおりです。
public class InvoiceLine
{
[Key]
public int Id { get; set; }
[Required]
public int Number { get; set; }
[Required]
public string Description { get; set; }
public int InvoiceId { get; set; }
public Invoice Invoice { get; set; }
}
問題: この簡単なクエリを実行すると、以下のエラーが発生しました。
データの取得中にエラーが発生しました。プロパティが見つかりません: タイプの行: 請求書
問題は orderBy 句の周りにあります。Invoice と InvoiceLine の間には 1 対多の関係があるため、この場合は order by を実行できないようです。
私の質問: 請求書の行を番号順に並べ替えるにはどうすればよいですか?
ありがとう。