2013-08-02 48 views

回答

2
if(CustomeSettings == null) CustomerSettings = 
            new Collection<ProductCustomization>(); 

var cat = CustomSettings.FirstOrDefault(r=>r.CategoryId == catID && 
              r.CustomizationType == catType); 
if(cat!=null) 
{ 
    cat.DefaultFreeCount = freeCount; 
    cat.ProductID = this.ProductID; 
} 
else 
{ 
    this.CustomSettings.Add(new ProductCustomization() 
     { 
      CategoryID = catId, 
      CustomizationType = catType, 
      DefaultFreeCount = freeCount, 
      ProductID = this.ProductID 
     }); 
} 
+0

如果我需要檢查2條件它,然後像什麼CATD和catype都需要檢查。 – NoviceToDotNet

+0

我編輯了答案 –

+0

BUt如果CustomSettings已經爲空,該怎麼辦? – NoviceToDotNet

1
if(this.CustomSettings.Any(x=>x.CategoryID == catId)) 
{ 
    //Update 
} 
else 
{ 
    //Add 
} 
相關問題