Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to exclude an auto generated column in UpdateAsync call

Mahesh453261Mahesh453261 Member ✭✭
edited October 24 in Xamarin.Forms

Hi,

Greetings!

I have an Azure Mobile Service Client in backend. I am making an update to DB by UpdateAsync Call which throws the below Error.

Error : The column "OrderId" cannot be modified because it is either a computed column or is the result of a UNION operator.

Column OrderId is an Auto Generated column in DB.

I have tried [NotMapped] [DataBaseGeneratedOption] in my model and nothing seems to be working.

**Code: **
await App.client.GetTable().UpdateAsync(orderupd);

Model Class:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace SevenDashboard.Models
{
public class Orders
{
public string id { get; set; }
public string HotelId { get; set; }
public string TableName { get; set; }
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Computed)]
public string OrderId { get; set; }
public string OrderedBy { get; set; }
public string OrderType { get; set; }
public string OrderStatus { get; set; }
}

Please help!

Regards,
Mahesh B.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai
    edited October 26

    We can't update a column which has been marked as the Computed.
    Its value will be the result of the function on the server side.
    How did you execute the update instruction? Try to remove the OrderId column value when updating.

  • Mahesh453261Mahesh453261 Member ✭✭

    Below is the update statement:

    var orderupd = await App.client.GetTable().where(x=>x.OrderId);

    orderupd.OrderStatus ="Closed"

    await App.client.GetTable().UpdateAsync(orderupd);

Sign In or Register to comment.