public static Account ExtractDirtyDbModels(this AccountOverview accountOverview) { Account returnAccount = null; if (accountOverview.IsDirty || accountOverview.IsChildDirty) { returnAccount = accountOverview.ToDbModel(); foreach (var accountCategoryOverview in accountOverview.AccountCategories) { if (accountCategoryOverview.IsDirty || accountCategoryOverview.IsChildDirty) { var accountCategory = accountCategoryOverview.ToDbModel(); foreach (var accountActualOverview in accountCategoryOverview.AccountActuals) { if (accountActualOverview.IsDirty || accountActualOverview.IsDeleted) { accountCategory.AccountActuals.Add(accountActualOverview.ToDbModel()); } } returnAccount.AccountCategories.Add(accountCategory); } } } return(returnAccount); }