JsonConvert.DeserializeObject to populate Llblgen Entity with field from computed column

Posts   
 
    
like2175
User
Posts: 83
Joined: 27-Mar-2006
# Posted on: 12-Nov-2019 16:14:01   

Hi

I am passing LLBLgen Entities to and from a WEBAPI successfully, however I hit a problem when the Entity relates to a SQL table with a computed column.

I have had to remove the ReadOnly flag in the designer to allow the Field that relates to the computed column to be populated by JsonConvert.DeserializeObject With ReadOnly set true, quite sensibly, no value is written to the field.

Now when I try to adapter.SaveEntity({toSave}) I get, quite sensibly again, an ORMQueryExecutionException: 'The column {column)name} cannot be modified because it is either a computed column or... '

Is there any easy solution?

C# Winforms front end WEB API 2.0 Middle Tier SQL 2014 back end LLBLGen 5.2.3 VS 2019.

The following may help for context:


public async Task<int> SaveAsync(IEntity2 entityToSave, string url)
        {
           var contentMessage = new StringContent(JsonConvert.SerializeObject(entityToSave, _jsonSettingProvider.GetJsonConfiguration()), Encoding.UTF8, "application/json");

            var response = _httpClientWithRetryProvider.Client().PutAsync($@"{url}/Single/", contentMessage).Result;
etc.



 public async Task<T> GetWebApiValueAsync<T>(string url)
        {
            using (var response = _httpClientWithRetryProvider.GetAsync($@"{url}"))
            {

                var result = await response.Content.ReadAsStringAsync();
                if (response.IsSuccessStatusCode)
                {
                    var retVal = JsonConvert.DeserializeObject<T>(result, _jsonSettingProvider.GetJsonConfiguration());
                    return retVal;   
                }

Thanks in advance Graham

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 12-Nov-2019 18:33:26   

Before saving, set the EntityField.IsChanged property to false, for the compute column field of the entity.