如何使用 Subsonic 3 和 SimpleRepostitory 设置 POCO?或者大会在哪里?
是否有地方详细介绍了在 SubSonic 3 中使用 SimpleRepository 时如何设置 POCO?听起来像是约定优于配置,但我找不到解释该约定的地方。
http://www.subsonicproject.com/docs/Conventions 看起来像是针对 2.0 的,并且也被标记为不完整。 (顺便说一句:我很乐意帮助将文档重新组织为更多 2.0 和 3.0,因为当前文档对它们所指的版本有点混乱。)
例如,我想知道如何设置建立
一对一关系
User <=>配置文件
class User {
Id
ProfileId instead of Profile? or is Profile profile possible?
}
class Profile {
Id
UserId instead of User? or is User user possible?
}
一对多关系
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?
}
多对多
我猜我需要设置一个多对多表?
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?
}
在示例解决方案中,似乎没有设置这些,所以我想知道你会如何去做(我的猜测继续示例):
一对一的
User.Profile
r.Single<Profile>(p=>p.User == userId);
父母对一对多的
Post.User
id = r.Single<Post>(postId).UserId;
r.Single<User>(id); // which kind of stinks with two queries, JOIN?
孩子一对一-多
User.Posts
r.Find<Post>(p=>p.UserId == userId)
或多对多
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? :)
我认为必须有一种方法可以不进行两个查询,并且这些属性已经以某种方式自动生成。说实话,虽然我昨晚只有一个小时的时间玩所有的东西,所以我有点害怕罗布对我大喊大叫。对不起! :P
如果这些不是自动生成的,那么 3.0 的视图和存储过程在哪里?当你在做的时候,请给我一个链接。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是您最好的起点:
http://subsonicproject.com/docs/Using_SimpleRepository
关系由您和我们在代码中设置不要将这些转发到数据库(但希望很快)。理想情况下,您可以根据需要设置模型,当您准备好后,您可以手动“巩固”数据库中的关系。这是为了减少开发过程中的摩擦——构建网站时数据完整性并不是真正需要担心的事情。
也就是说,我知道人们想要这个功能 - 我只需要构建它。
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.