X DevApi - C# strongly typed objects
Posted by: Satish Bodake
Date: October 25, 2022 11:10AM

I'm using MySQL 8.0.28 enabled X DevApi plugin listening on port 33060. I'm looking for Api reference examples that demonstrate on how to store strongly typed objects as a document in a given schema.

Ex.

public class Payload
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string id { get; set; }
public int JobId { get; set; }
public Dictionary<string, Core> Data { get; set; }
}

public class Core
{

public string[] Meta { get; set; }
}


#### Insert into Doc Store

public async Task InsertDocumentAsync(Payload entity)
{
if (entity is null)
{
throw new ArgumentNullException(nameof(entity));
}

try
{

var result = await _dbCollection.Add(entity).ExecuteAsync();
entity.id = result.GeneratedIds[0];
}
catch (Exception ex)
{
_logger.LogError("Error inserting into mysql doc store", ex);
}
}


It inserts a document successfully with following values -

column - doc value - '{\"_id\": \"00006356dc0a0000000000001908\"}'
column - _id value - BLOB
column - _json_schema value - '{\"type\": \"object\"}'


I could fetched the document but unable to cast result to class type "Payload"

#### fetch doc from store

var d = dbCollection.GetOne(guid);
var doc = Utf8Json.JsonSerializer.Deserialize<Payload>(d.ToString());


Is there any other methods to do above operations? I've been dealing with pretty complex type structure which has multiple complex properties under root type.

Options: ReplyQuote


Subject
Written By
Posted
X DevApi - C# strongly typed objects
October 25, 2022 11:10AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.