1

考虑 LINQ 中的这段代码(请关注 var list2):

var list1 = .......  /* This linq doesnt matter. Just for clarify that it is used in the below linq */

var list2 = dba.OrderForm
    .Where(q => q.OrderPriority.OrderPriorityID == orderpriorityID
        && q.StockClass.StockClassID == stockclassID
        && dba.AuditTrailLog.Where(log => q.OrderID == log.ObjectID)
        .Any(log => log.ColumnInfoID == 486
            && log.OldValue == "2"
            && log.NewValue == "3")
            && dba.AuditTrailLog.Where(log2 => q.OrderID == log2.ObjectID)
            .Any(log2 => log2.ColumnInfoID == 487
                && log2.OldValue == "1"
                && log2.NewValue == "2")
                && lista.Contains(q.OrderID));

这样,我在 list2 中有一个属于OrderForm模型的记录列表。我需要将它传递给另一个名为ViewResult

我需要的是获取log2.ModificationDate属于AuditTrailLog表的变量,但它不包含在OrderForm模型中

List<ViewResult> vr = new List<ViewResult>();

foreach (OrderForm o in list2)
{
    ViewResult r = new ViewResult();
    r.NumOrden = o.FormNo;
    r.Title = o.Title;
    r.Com = o.OrderPriority.Descr;
    r.OClass = o.StockClass.Descr;
    r.RodT =   /*  <<------ Here is where I need to assign log2.ModificationDate

    vr.Add(r);              
}  

谢谢。

4

1 回答 1

3

我的理解是AuditTrailLog在您获取数据时关系为空。你想用相关数据填充它。

你必须Include像这样的表:

(这意味着您正在join使用 sql)

var list2 = dba.OrderForm.Include("AuditTrailLog")...

它们之间的关系很重要。“一对多”或“多对一”。使用AuditTrailLogAuditTrailLogs根据您的关系。

于 2013-05-22T11:01:49.423 回答