public WasteFactor Edit(WasteFactor factor) { factor.ModifiedOn = DateTime.Now; WasteFactor dbfactor = Single(factor.ID); // get the database columns which need to be updated var databaseMembers = db.Mapping.MappingSource.GetModel(typeof(BizzyQuoteDataContext)).GetMetaType(typeof(WasteFactor)).DataMembers .Where(d => d.IsAssociation == false && d.IsDbGenerated == false && d.IsPersistent == true); // reflect to get instances of the entity preoprties var editProperties = from p in dbfactor.GetType().GetProperties() join m in databaseMembers on p.Name equals m.Name select p; // copy the values PropertyInfo[] editProps = editProperties.ToArray(); foreach (PropertyInfo propertyInfo in editProps) { propertyInfo.SetValue(dbfactor, propertyInfo.GetValue(factor, null), null); } db.SubmitChanges(); return(dbfactor); }
public WasteFactor Create(WasteFactor factor) { factor.CreatedOn = DateTime.Now; factor.ModifiedOn = DateTime.Now; db.WasteFactors.InsertOnSubmit(factor); db.SubmitChanges(); return(factor); }