Creating Simple Serial Number in C# and Entity Framework

Hi Kids,

If you want to create a simple serial generator with prepended Characters in C#, here is how you do it Kids.

    var guestCode = "SERIAL00000000";
    // coming from newly created database entry from using Entity Framework
    var customerNumber =;
    // this code is self explainatory or do I have to explain it for you? c'mon...
    guestCode = guestCode.Remove(guestCode.Length - customerNumber.Length);
    // you know what's going on right?
    guest.GuestNumber = guestCode + customerNumber.ToString();

   // then apply the update to database using the db Context
    db.Entry(guest).State = EntityState.Modified;

Ciao Kids!

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *