0

I have the following code to insert my POCO into a LiteDB instance.

Here is the POCO:

public class FileTranslationData
{
    public Guid Id { get; set; }
    public string FileLocation { get; set; }
    public string FileJSONLocation { get; set; }
    public int TranslationRetries { get; set; }
    public string TranslationStatus { get; set; }
    public string TranslationId { get; set; }
    public string FileTranslationURL { get; set; }
}

And here is the call to insert the data into the collection:

public string SaveFileTranslationStatus([FromServices] LiteDbContext db, FileTranslationData data, string Collection)
{
    var files = db.Context.GetCollection(Collection);
    files.Insert(data);
    files.EnsureIndex(x => x.id);
    return null;            
}

The files.Insert(data) line is throwing an error:

Arguement 1: cannot convert from 'LargeFileDownload.Models.FileTranslationData' to 'LiteDB.BsonDocument'

I have read the documentation for LiteDB and it says it can handle inserting POCO objects. I have an ID field that I want to sent the index on as well. What am I missing here?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
john
  • 1,273
  • 3
  • 16
  • 41
  • 1
    Why `return null;`? Why not just make the method void? – mason Aug 05 '19 at 19:44
  • I'm stubbing in this code right now, so I am returning null until I get the rest of the code in place to return the correct value. I have updated the code to return the Id after the insert into the file. – john Aug 06 '19 at 15:22

1 Answers1

3

Well that was a quick fix, and this is entirely my fault, but I am posting my answer here for others who may have made the same mistake I did. This line

var files = db.Context.GetCollection(Collecton);

Needed to be changed to:

var files = db.Context.GetCollection<FileTranslationData>(Collecton);

Without passing the collection type, it assumes a generic Bson document. Once I put in the document type, it all worked.

john
  • 1,273
  • 3
  • 16
  • 41