繁体   English   中英

MongoDB C#驱动程序 - 将字符串列表表示为ObjectId列表

[英]MongoDB C# Driver - Representing a list of string as list of ObjectId

因此,使用MongoDB和它的C#驱动程序,我在UsersProjects之间有多对多关系,并让它们像这样相互引用(基于本文 - 多对多关系 ):

public class User
{
    // other props....
    ICollection<string> ProjectIds {get; set;}
}

public class Project
{
    // other props....
    ICollection<string> UserIds {get; set;}
}

如您所见,我使用string而不是ObjectId 我知道你可以通过在映射中使用SetRepresentation(BsonType.ObjectID)或通过数据注释来实现这一点,但是,使用字符串列表,MongoDB会抛出一个BsonSerializationException

那么,我如何告诉MongoDB将字符串列表表示为ObjectIds? 关于这个问题的任何意见将不胜感激。 谢谢!

在mongodb我使用List<string>它将作为[]数组存储在集合中,并且可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM