使用 Subsonic 3.0 高级模板
我已经尝试在项目中使用 Subsonic 高级模板有一段时间了,但大多数时候我发现自己在编写存储过程,因为我找不到在代码中执行此操作的正确方法。
Subsonic 为我的数据库表创建了相应的对象,并为外键创建了每个对象内的 IQueryable 字段。默认情况下不会加载这些字段,并且在访问它们时会执行新的 SQL 查询。
1-有没有一种方法可以在一个查询中获取所有数据(深度负载)?
这些字段也不能被分配。因此,当我想在维护页面中创建一个对象时,在将其保存到数据库之前,我无法将所有数据放入该对象中:
Post post = new Post();
//get photos for this post
IList<PostPhoto> postPhotos = GetPostPhotos();
post.PostPhotos = postPhotos;
2- 是否可以拥有一个 Post 对象,其所有字段均通过用户输入设置?
考虑上面的 Post 对象并假设我已经成功分配了它的字段。现在我需要将其保存到数据库中。
3-使用 BatchQuery 是在一个查询中执行此操作的唯一方法吗?如果我在 PostPhotos 字段中有 4 张照片;其中 2 张是之前保存的,另外 2 张是新的,我可以使用 Update 方法来处理这些照片的添加和更新吗?
任何想法或链接表示赞赏。
干杯...
I've been trying to use Subsonic Advanced Templates in a project for a while but most of the time I find myself writing a Stored Procedure as I can't find a proper way of doing it in code.
Subsonic created corresponding objects for my DB tables and for foreign keys it created IQueryable fields inside each object. These fields are not loaded by default and a new SQL query is executed when you access them.
1- Is there a way to get all data in one query (deep load)?
Also these fields can not be assigned. So when I want to create an object in a maintenance page, I can't put all the data into this object before saving it in DB:
Post post = new Post();
//get photos for this post
IList<PostPhoto> postPhotos = GetPostPhotos();
post.PostPhotos = postPhotos;
2- Is it possible to have one Post object with all fields set from user input?
Think of the Post object above and assume I've successfully assigned its fields. Now I need to save it to the DB.
3- Is using BatchQuery the only way to do it in one query? If I have 4 photos in PostPhotos field; 2 of them previously saved and 2 of them new, can I use the Update method to handle both the adding and updating of these photos?
Any ideas or links are appreciated.
Cheers...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论