SubSonic 3.0 中的关系和延迟加载
我现在正在使用 SubSonic 3.0,它看起来非常简单(除了我仍然需要在 SimpleRepository 和 ActiveRecord 之间做出选择,但那是另一个故事了)。
然而,由于文档有点稀疏,我不确定它是否支持外部关系和延迟加载。 本质上,我有一个类发布:
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 这两者是相关的吗? 那就是我保存帖子的时候可以自动保存所有评论吗? 更重要的是,当我加载帖子时,我希望评论列表首先为空,然后在某个时候说“好吧,请立即填充它”。
我知道我可以在代码中手动管理它,但我只是想在进行手动工作之前知道 SubSonic 是否可以做到这一点。
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; }
}
and a class Comment:
public class Comment
{
public string Body { get; set; }
}
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".
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
疏? 你读过它们了吗?
ActiveRecord 可以根据 FK 确定您的关系(Linq 模板也可以),并将使用 IQueryable。 因此,您可以两全其美 - 如果您需要它们,它们就在那里。
如果您使用 Simple Repo - 不 - 这不会发生,而且都是手动的。
Sparse? Have you read them yet?
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.
If you use Simple Repo - no - this doesn't happen and it's all manual.
即使您使用的是简单存储库,也有一个用于管理外键的简单选项。 查看这篇文章了解细节。
There's a simple option for managing foreign keys, even if you're using the Simple Repo. Check out this post for the details.