3

关于如何用 .net 对象表示以下内容的任何想法?

{
    _id: ’T4Y...AC’, // base64-encoded ObjectId
    name: ’Rick’,
    profile: { ... age, location, interests, etc. ... },
    followers: {
    "T4Y...AD": { name: ’Jared’, circles: [ ’python’, ’authors’] },
    "T4Y...AF": { name: ’Bernie’, circles: [ ’python’ ] },
    "T4Y...AI": { name: ’Meghan’, circles: [ ’python’, ’speakers’ ] }
    }
}
4

1 回答 1

1

我想它可能看起来像

[DataContract]
public class data
{
    [BsonId]
    [DataMember(Order = 0]
    public BsonObjectId { get; set; }

    [DataMember(Order = 1]
    public string name { get; set; }

    [DataMember(Order = 2]
    public Profile profile { get; set; }

    [DataMember(Order = 3]
    public Dictionary<string,Follower> followers { get; set;}
}

[DataContract]
public class Profile
{
    [DataMember(Order = 0]
    public int age { get; set; }
    [DataMember(Order = 1]
    public string location { get ;set; }
    [DataMember(Order = 2]
    public string interests { get ;set; }
}

[DataContract]
public class Follower
{

     [DataMember(Order = 0]
    public string name { get; set; }
    [DataMember(Order = 1]
    public string[] circles
}

我相信 Mongo 和 WCF 都支持字典,所以是的,您可以将 Followers 更改为字典

于 2012-05-30T02:55:43.303 回答