使用Byte Array将简单的ASP.Net对象序列化为Bson,C#包装器

时间:2016-08-18 14:19:32

标签: c# asp.net mongodb

我有一个简单的ASP.Net对象来收集Mongo中存储的文件信息。 FileAttrib类已经填充。

public class FileAttrib
{
    public string Filename { get; set; }
    public long FileSize { get; set; }
    public string FileContent { get; set; }
    public string FileType { get; set; }
    public byte[] FileContents { get; set; }   
}

我已经尝试了几次迭代,将这个对象序列化为Bson而没有运气。这似乎很简单,但我遗漏了一些东西。

public async void AddDocumentToMongo(string db, FileAttrib fa)
{
    _client = MongoDbConnection.GetMongoClient();
    _database = MongoDbConnection.GetMongoDatabase(_client, db);
    var collection = _database.GetCollection<FileAttrib>("testInsert");

    var doc = BsonDocument.Create(fa);

    await collection.InsertOneAsync(doc);
}

错误在BsonDocumentCreate语句中创建:{&#34; .NET类型FileUpload.Models.FileAttrib无法映射到BsonType.Document。\ r \ nParameter name:value&#34;}

我不确定这意味着什么,但我认为解决这个问题必须相当简单 - 我现在还没有做好。

0 个答案:

没有答案
相关问题