6

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.

Michael Stum
  • 177,530
  • 117
  • 400
  • 535

2 Answers2

4

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.

  • Hey Rob... But should there be a CommentID with Active record solution you suggest (to have an actual FK in your class) or is it possible to use a property of type Comment for the relation? – Robert Koritnik Jul 12 '09 at 07:40
  • Hi, I've looked at the "Docs" Section on SubSonic, which has http://subsonicproject.com/docs/Using_ActiveRecord - Maybe I was not clear enough: Can ActiveRecord create my Schema for me? Or do I create it manually and then AR will automagically use the FK? – Michael Stum Jul 12 '09 at 11:57
  • 1
    You create it manually and then SubSonic will automagically generate the object and use the FK – Adam Cooper Jul 12 '09 at 20:07
  • 1
    Yes - AR works from the DB out, SimpleRepo works the other way. –  Jul 13 '09 at 19:34
3

There's a simple option for managing foreign keys, even if you're using the Simple Repo. Check out this post for the details.

Jerod Venema
  • 44,124
  • 5
  • 66
  • 109