2009-08-03 68 views

回答

2

只需添加[SubSonicIgnore]以上LineCost

所以

 [SubSonicIgnore] 
     public decimal LineCost 
     { 
      get { return Qty * Convert.ToDecimal(LineCost); } 
     } 

爲LineCost被映射到數據庫發生這種情況。

1

爲什麼不只是做對象定義本身的測算?

所以

public class OrderLine 
    { 
     public int OrderId { get; set; } 
     public int Qty { get; set; } 
     public decimal ProductPrice { get; set; } 
     public decimal LineCost 
     { 
      get { return Qty * Convert.ToDecimal(LineCost); } 
     } 
    } 
+1

感謝波奇,我會嘗試這一個。這是正確的方式還是隻是解決方法? – 2009-08-03 11:18:10

+0

失敗:SQLEXCEPTION:無效的列名稱LineCost「 @Podge,記得我使用SimpleRepository和手工製作我的類/對象 – 2009-08-03 11:42:42

0

,我只能看到使用anoynmous類型的方式,然後你將不得不類型轉換爲訂單行(它不是很漂亮)

   var x =from o in repo.All<OrderLine>()  
        select new 
        { 
         OrderId = o.OrderId, 
         ProductPrice = o.ProductPrice, 
         Qty = o.Qty, 
         LineCost = o.ProductPrice * o.Qty 
        }; 


      List<OrderLine> orders = null; 
      foreach (var t in x) 
      { 
       orders.Add(new OrderLine 
       { 
        LineCost = t.LineCost, 
        OrderId = t.OrderId, 
        ProductPrice = t.ProductPrice, 
        Qty = t.Qty 
       }); 

      } 
相關問題