views:

184

answers:

1

Is there someplace that details how to setup your POCO's when using the SimpleRepository with SubSonic 3? It sounds like it's convention over configuration, but I can't find where that convention is explained.

http://www.subsonicproject.com/docs/Conventions looks like it was meant for 2.0, and is also marked incomplete. (BTW: I'd love to help reorganize the docs into more a 2.0 and 3.0 as the current docs are a bit confusing on which version they are referring to.)

For instance I'd like to know how I'd go about setting up a

one-to-one relationship

User <=> Profile

class User {
  Id
  ProfileId instead of Profile? or is Profile profile possible?
}

class Profile {
  Id
  UserId instead of User? or is User user possible?
}

One-to-many relationship

class User {
  Id
  IList<Post> Posts (?) or IList<int> PostIds (?) or is this implied somehow?  or is this just wrong?
}

class Post {
  Id
  UserId instead of User? or is User user possible?
}

Many-to-many

I'm guessing I'd need to setup a many to many table?

class User {
  IList<Blog> Blogs (?) or IList<int> BlogIds (?) or is this implied somehow?
}

class BlogsUsers {  // Do I have to create this class?
  UserId
  BlogId
}

class User {
  IList<User> Users (?) or IList<int> UserIds (?) or is this implied somehow?
}

In the example solution it doesn't seem like these are set so I'm wondering how you'd go about doing a (my guess proceeds example):

one-to-one

User.Profile

r.Single<Profile>(p=>p.User == userId);

parent on one-to-many

Post.User

id = r.Single<Post>(postId).UserId;
r.Single<User>(id); // which kind of stinks with two queries, JOIN?

children on one-to-many

User.Posts

r.Find<Post>(p=>p.UserId == userId)

or many-to-many

User.Blogs

ids = r.Find<BlogsUsers>(bu=>bu.UserId == userId);
r.Find<Blog>(b=>b.BlogId == ids);  // again with the two queries?  :)

Blog.Users

ids = r.Find<BlogsUsers>(bu=>bu.BlogId == blogId);
r.Find<User>(u=>u.UserId == ids);  // again with the two queries?  :)

I would assume that there's got to be a way to not have the two queries and for these properties to already be autogenerated in some way. Truth be told though I did only have an hour to play with everything last night so I am a little afraid of Rob yelling at me. I'm SORRY! :P

If these are not autogen'd then where are views and store procedures for 3.0? Please give me a link for those as well while you're at it fellow SO'er.

+1  A: 

This is probably your best place to start: http://subsonicproject.com/docs/Using%5FSimpleRepository

Relationships are setup in code, by you, and we don't carry those forward to the DB (yet - hopefully soon). Ideally you setup your model as you need to and when you're ready you go and manually "solidify" your relationships in the DB. This is to reduce friction during development - data integrity isn't really something to worry about when building a site.

That said, I know people want this feature - I just need to build it.

Rob Conery
Well maybe this could be done within a template or something? My poco would contain the table columns, then a tt would generate a partial that would have the code that would contain the foreign key relationships with property names? Like:Blogs { get { foreach(User user in r.Find<User>(u=>u.UserId == this.Id)) { ids.Add(user.Id);}r.Find<Blog>(b=>b.BlogId.In(ids));}}wouldn't this work?
rball
Maybe if you explain how you'd build it you wouldn't need to be the one building it. Maybe we could pitch in :)
rball
The code is available for all to see - I can only do so much friend.
Rob Conery
Yeah, I understand. It's just hard for someone like me that doesn't know the codebase at all to dive in and implement what seems to be a complex functionality. I think I mean more along the lines of "What needs to happen next, here's what I need help with". Right now I have no clue what you guys are working on or what small things I could do to help. I have started to help with your documentation as I know that's at least a pain, and it correlates with my experiences in getting SubSonic rolling. Hope that helps.
rball