CodeFluentDuplicateException what i'm i missing

63 Views Asked by At

I have problem getting a "CodeFluent.Runtime.CodeFluentDuplicateException" and i'm probably missing something fundamental.

However i first followed this blog about using Servicestack and codefluents and made my own template. I have no problems to get entities but doing a put give me an exception mentioned.
Ok maybe i have done some wrong in my template so i took another approach looking for answers i found a "complete" project using Webapi and a template, ready to use. Generate ASP .NET Web API Controllers using Templates.
This generates all the controllers and seems to work. However i have the same exeption when using the "put".

This is an example of generated controller code for Put

 public HttpResponseMessage Put([FromBody]Country value)
    {
        if (value == null || !value.Save())
        {
            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }
        return Request.CreateResponse(HttpStatusCode.OK, value);
    }

This is how i use the controller above inside a Xamarin.Forms solution.

public async Task UpdateAsync(Country update, bool isNewItem=false)
    {
        HttpClient client = new HttpClient();

        // RestUrl = http://developer.xamarin.com:8081/api/todoitems{0}
        var uri = new Uri(string.Format(Constants.RestUrl2, update.Id));

        try
        {
            var json = JsonConvert.SerializeObject(update);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage response = null;
            if (isNewItem)
            {
                response = await client.PostAsync(uri, content);
            }
            else
            {
                response = await client.PutAsync(uri, content);
            }

            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine(@"              TodoItem successfully saved.");
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(@"              ERROR {0}", ex.Message);
        }
    }

Any suggestions of what i'm missing?

Thanks for any help //Greg

1

There are 1 best solutions below

0
On

I got the answer from the softfluent support

".. Another case of duplicate exception is when you enable optimistic concurrency and the RowVersion of the instance you are updating is null. In this case, the stored procedure will insert the row instead of updating it. .."
Changeing the concurrencyMode=None did the trick