【发布时间】:2019-08-06 20:36:24
【问题描述】:
我正在尝试开始使用 mongo db。但是当我尝试使用字符串 Id = null 添加新元素时,因为它是新元素,所以它给了我一个错误
public abstract class BaseEntity
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public abstract string CollectionName { get; }
}
每当我尝试通过运行添加时:
public string InsertOne(TEntity newEntity)
{
if(newEntity == null)
{
throw new ArgumentNullException(nameof(newEntity));
}
var collection = _mongoContext.Collection<TEntity>();
collection.InsertOne(newEntity);
return newEntity.Id;
}
我每次尝试都得到 '0' 不是有效的 24 位十六进制字符串。
【问题讨论】:
标签: c# mongodb mongodb-query