Question

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.

Was it helpful?

Solution

This is probably your best place to start: http://subsonicproject.com/docs/Using_SimpleRepository

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top