Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I had develop blazorWASM aplication.

In this appllication I want to generate unique order id thats why I had choose snowflakeid to avoid duplicate orders

I had used snowflakeid nuget package as below procedure https://www.nuget.org/packages/SnowflakeIDGenerator

I had generate the snowflakeid using machineid and customepoch. snowflakid type is long

that snowflakeid want to maintain in db and I had passed the snowflakeid through api using serialization process at the time snowflakeid value changed like

snowflakeid original value: 526688986857484300

snowflakeid changed value:526688986857484304

For suppose before seralization If i changed the type to string at the time also snowflakeid changed

I know Issue happened If i do change the long to string thats why I had ignore type conversion. I know largeinter numbers or snowflake id changed when conversion thats why i had ignored but when seralization also issue happened

C#
public async Task<Orders> Updateorder(Orders order, IHttpClientFactory clientFactory)
    {
        var getorder = new Orders();


        try
        {
            var client = clientFactory.CreateClient("WebAPI");
            var updaterequest = new HttpRequestMessage(HttpMethod.Post, "api/Orders/UpdateOrder");
            POSOrderRequest request = new POSOrderRequest();
            request.Baseobject=order;
            string serializedData = JsonConvert.SerializeObject(request);
            StringContent content = new StringContent(serializedData, Encoding.UTF8, "application/json");
            var response = await client.PostAsync(updaterequest.RequestUri, content);
         
            if (response.IsSuccessStatusCode)
            {
                var updatereponse = response.Content.ReadAsStringAsync().Result;


                UpdateOrderapireposne apires = JsonConvert.DeserializeObject<UpdateOrderapireposne>(updatereponse);


                getorder = apires.BaseObject;


            }


        }
        catch (Exception ex)
        {


        }


        return getorder;
    }




I want to maintain Snowflake id value preserved when passing to webapi

Please help me. Thank you.

What I have tried:

I want to maintain Snowflake id value preserved when passing to webapi
Posted
Comments
Richard MacCutchan 24-Dec-23 6:49am    
You should let the database library manage unique ids.
Krishna Veni 24-Dec-23 9:33am    
Snowflake id value not preserved when passing to webapi
[no name] 24-Dec-23 12:25pm    
Since it's that long, use a GUID function which is more or less "sure" to be unique. Easier to "read" too.

https://learn.microsoft.com/en-us/dotnet/api/system.guid.newguid?view=net-8.0

https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumbergenerator?view=net-8.0
jochance 30-Jan-24 19:23pm    
Yeah my ? to this ? is why does OP hate GUIDs?
Krishna Veni 25-Dec-23 2:53am    
I dont want duplicateid any time thats why i did not used guid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900