Lazy loading in MongoDB with NoRM

前端 未结 2 811
猫巷女王i
猫巷女王i 2021-01-20 09:47

I have a model similar to this: (simplified)

Question:

public class Question
{
    public string QuestionID { get; set; }

    publi         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 10:00

    I appreciate that this is an old thread, but other people may still be finding it (as I did). Lazy loading is both possible in MongoDB and supported by the C# driver.

    Check out the following classes: LazyBsonDocument and LazyBsonArray

    From the C# Driver tutorial documentation : "The lazy classes are special in that they defer the deserialization of BSON until it is needed. This is useful for when you only need a field or two out of a complex document because it will not incur the cost of deserializing the entire document or array, but just the pieces that are necessary. This deserialization occurs a level at a time."

    At the time of writing the tutorial document can be found here: http://docs.mongodb.org/ecosystem/tutorial/use-csharp-driver/

    The example given is very similar to the question in that it involved a nested collection, so it looks like the list of answers could indeed be lazy loaded if that was desirable.

    Hope this helps someone,

    Nick

提交回复
热议问题