Is it your desire that the “highest” (alpha-numberically) key with a specified prefix be incremented?
Like if you have UD30 records with Key1: 1001
, 1100
, TEA111
, and TEA1111
And you add a record with prefix TEA
, the Key1 field for that ne record would TEA1112
??
"TEA"+"1112"
where the "1112"
is 1) "1111"
converted to a number, 2) that number incremented by 1, and finally 3) converted back to a string
Can you just make Key1 your prefix in Key2 the sequence?
That would make things a tad easier.
Either way, you have the issue of the number of digits in the “numeric part”, and the fact that the whole thing is a string. sorting the numeric part would go:
1, 10, 100, 101, 102, ...109, 11, 110, 111, 112... 119, ...
So you might want to pad the numeric part with leading zeros. Then the “Order By” in the LINQ query would be straightforward.