作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
一个简单的问题,如何将 BsonValue 的默认值设置为空列表
[BsonElement("Networks")]
[BsonRepresentation(BsonType.String)]
[BsonIgnoreIfNull]
[BsonDefaultValue(new List<SocialProfileTypes>() { })]
[BsonIgnoreIfDefault]
public UniqueList<SocialProfileTypes> Networks
{
get { return networks; }
set { networks = value; }
}
作为[BsonDefaultValue(new List<SocialProfileTypes>() { })]
给出语法错误
Error 8 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
最佳答案
这是 C# 语言约束。属性中的值必须是编译时常量。
关于 mongodb 驱动,你需要使用代码来设置这样的值(注意:没有编译这个,但它会类似)
BsonClassMap.RegisterClassMap<MyClass>(cm =>
cm.AutoMap();
cm.MapMember(x => x.Networks).SetDefaultValue(new List<SocialProfileTypes>())
});
我相信这无论如何都会失败,因为 List 没有实现或继承自 UniqueList,因此您也必须修复它。
关于mongodb-.net-driver - BsonDefaultValue 设置为空列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26671182/
一个简单的问题,如何将 BsonValue 的默认值设置为空列表 [BsonElement("Networks")] [BsonRepresentation(BsonType.Stri
我是一名优秀的程序员,十分优秀!