Lazy loading in MongoDB with NoRM

前端 未结 2 774
猫巷女王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 09:48

    OK, the concept of "Lazy Loading" is mostly foreign to a database like MongoDB. Take a look at your schema: Question has a List of Answers.

    In an RDBMS the "lazy" part allows you to load "the list" separately from the original. There are actually two queries happening, you're just trying to delay the second query.

    In MongoDB there's only one query happening. The Answers are embedded inside of the question, so your request for Questions automatically includes the list of Answers.

    Please take a look at the NORM samples for a better example of this: http://normproject.org/samples

    The basic point is that the structure you provided is no longer multiple tables. It's just one collection with embedded documents. So the concept of "Lazy Loading" is really unnecessary because you can't "Lazy Load" one query.

提交回复
热议问题