>var lastLocSuffix = _salespointAdapter.GetAll().Max(sp=>sp.LocSuffix); > Int16 newSuffix = 1; > if (lastLocSuffix != null) > { > newSuffix = lastLocSuffix++; > } > > salespoint.LocSuffix = newSuffix;The ++ operator after the variable is done after the assignment (that is, the assignment happens first, then lastLocSuffix is incremented). So if GetAll().Max() returned 1, newSuffix would be assigned a 1 (not a 2).
newSuffix = ++lastLocSuffix;I'd actually end up trying to write the above as:
var lastLocSuffix = _salespointAdapter.GetAll().Max(sp=>sp.LocSuffix) ?? (short)0;
salespoint.LocSuffix = ++lastLocSuffix;
actually, this is probably easier to understand and avoids the assignment to lastLocSuffix which probably isn't needed anyway:var lastLocSuffix = _salespointAdapter.GetAll().Max(sp=>sp.LocSuffix) ?? (short)0; salespoint.LocSuffix = lastLocSuffix + 1;