问题描述
我目前正在使用 SubSonic 3.0,它看起来非常简单(除了我仍然需要在 SimpleRepository 和 ActiveRecord 之间做出决定,但那是另一回事了).
I'm playing around with SubSonic 3.0 at the moment, and it looks really straight-forward (except that I still have to decide between SimpleRepository and ActiveRecord, but that's another story).
但是,由于文档有点稀疏,我不确定它是否支持对外关系和延迟加载.基本上,我有一个班级帖子:
However, as the documentation is a bit sparse, I am not sure if it supports foreign-relationships and lazy-loading. Essentially, I have a class posting:
public class Posting {
[SubSonicPrimaryKey]
public Guid InternalId { get; set; }
public string Title { get; set; }
public string Body { get; set; }
public DateTime? PostingDate { get; set; }
public List<Comment> Comments { get; set; }
}
和一个班级评论:
public class Comment
{
public string Body { get; set; }
}
如您所见,发布有一个评论列表.我能以某种方式告诉 SubSonic 这两者是相关的吗?那就是我保存帖子的时候可以自动保存所有的评论?更重要的是,当我加载帖子时,我希望评论列表一开始是空的,然后说好的,请现在填写".
As you see, Posting has a List of Comments. Can I somehow tell SubSonic that these two are related? That is that I can automatically save all Comments when I save the Post? And more importantly, when I load a Posting, I'd like the List of Comments to be empty at first, and at some point say "Okay, please populate it now".
我知道我可以在代码中手动管理它,但我只是想在我进行手动工作之前知道 SubSonic 是否可以做到这一点.
I know I can manually manage this in Code, but I just like to know if SubSonic can do that before I do the manual work.
推荐答案
稀疏?你读过吗?
ActiveRecord 可以根据 FK(Linq 模板也可以)确定您的关系,并将使用 IQueryable.因此,您可以两全其美 - 如果您需要它们,它们就在那里.
ActiveRecord can determine your relationships based on FKs (so can the Linq Templates) and will use IQueryable. So you get the best of both worlds - they're there if you need them.
如果您使用 Simple Repo - 不 - 这不会发生,而且都是手动操作.
If you use Simple Repo - no - this doesn't happen and it's all manual.
这篇关于SubSonic 3.0 中的关系和延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!