Skip to main content
Solved

C# SDK Update data in RAW


Forum|alt.badge.img+1

Hi All,

I am trying to update data in RAW table. I am using below code but after executing it either column values are not modified or sometimes all the columns shrink under one columns as ({} columns) and column data is also not updated in that case.

 

var row = confModel.RawRow as RawRow<Dictionary<string, JsonElement>>;
if (row == null)
{
    return;
}

var currentDate = DateTime.Now;
var utcDate = currentDate.ToUniversalTime().ToString("u").Replace(" ", "T");
row.Columns[UpdatedBy] = GetJsonElement(JsonValue.Create("SYSTEM"));
row.Columns[SimulationStatus] = GetJsonElement(JsonValue.Create(status.ToString()));
row.Columns[UpdatedDate] = GetJsonElement(JsonValue.Create(utcDate));
var rawRowCreateColl = new List<RawRowCreate<RawRow<Dictionary<string, JsonElement>>>>();
var rawRowCreate = new RawRowCreate<RawRow<Dictionary<string, JsonElement>>>();
rawRowCreate.Key = confModel.RowKey;
rawRowCreate.Columns = row;
rawRowCreateColl.Add(rawRowCreate);

try
{
    SdkClient.Raw.CreateRowsAsync(database, table, rawRowCreateColl);
}
catch (Exception e)
{
    Console.WriteLine($"Error: {e.Message}");
}

 

Best answer by Einar Omang

You are explicitly creating a `RawRowCreate<RawRow<Dictionary<string, JsonElement>>>`, in other words, a raw row where the columns are a full `RawRow`. You want to make it a `RawRowCreate<Dictionary<string, JsonElement>>`, and move only the `Columns` part of the retrieved row over.

View original
Did this topic help you find an answer to your question?

7 replies

Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img

@Adarsh Dhiman  can you change the try catch method as below and try again?

try
{
    await SdkClient.Raw.CreateRowsAsync(database, table, rawRowCreateColl);
    Console.WriteLine("Data updated successfully.");
}
catch (Exception e)
{
    Console.WriteLine($"Error: {e.Message}");
}

 


Forum|alt.badge.img+1
  • Author
  • Seasoned
  • 13 replies
  • April 1, 2024

@Mithila Jayalath External My method is not async so I am not using await on CreateRowsAsync.


Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img

@Adarsh Dhiman isn’t the CreateRowsAsync method is an async mothod in the Cognite SDK to create rows in a table? 


Forum|alt.badge.img+1
  • Author
  • Seasoned
  • 13 replies
  • April 1, 2024

@Mithila Jayalath External In case if you are writing non async code you can call async code without await and can use Wait on that task. I missed that wait. Let me try with it.

var createRowTask = SdkClient.Raw.CreateRowsAsync(database, table, rawRowCreateColl);
createRowTask.Wait();


Forum|alt.badge.img+1
  • Author
  • Seasoned
  • 13 replies
  • April 1, 2024

After update all the columns shrink into one.

 


  • Practitioner
  • 68 replies
  • Answer
  • April 2, 2024

You are explicitly creating a `RawRowCreate<RawRow<Dictionary<string, JsonElement>>>`, in other words, a raw row where the columns are a full `RawRow`. You want to make it a `RawRowCreate<Dictionary<string, JsonElement>>`, and move only the `Columns` part of the retrieved row over.


Forum|alt.badge.img+1
  • Author
  • Seasoned
  • 13 replies
  • April 4, 2024

@Einar Omang Thanks it worked.


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings