BLToolkit 相当于 L2S 中的 LoadWith
使用 Linq to SQL 时,可以使用 DataLoadOptions 指定要加载的“子”对象。 BLToolkit 有类似的技术吗?
很高兴使用 BLT 我可以直接创建 BO,例如:
from p in db.Parent
select new Parent
{
ParentId = p.ParentId,
Child = p.Child
};
但是按照这条路线,在创建整个 Child 对象时,我需要指定 Parent 中的每个字段(即 ParentId、ParentName、ParentDob 等),
谢谢。
When working with Linq to SQL you can use DataLoadOptions to specify which "child" objects to load. Is there a similar technique with BLToolkit?
It's nice that with BLT I can create the BO directly, like:
from p in db.Parent
select new Parent
{
ParentId = p.ParentId,
Child = p.Child
};
however going this route, while the entire Child object is created, I would need to specify every field in Parent (i.e. ParentId, ParentName, ParentDob, etc.)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不完全像 LoadWith,但在我看来,下面的方法更好/更干净(不那么神奇)。在您的 BO 中创建一个如下所示的静态函数:
现在您需要像这样编写 LINQ 查询:
因此,我们让静态函数返回“p”,而不是“select p”或“select new Parent()”还要在返回之前将 Child 对象分配给“parent.Child”。只要您的关联设置正确(BLToolkit.Mapping.Association),p.Child 也会告诉 BLT 加入到 Child 表。你还可以走得更远,iepChild.Friends.etc。
Not exactly like LoadWith, but in my opinion the approach below is even better / cleaner (less magic). In your BO make a static function that would look like this:
Now you'd need to write your LINQ query like this:
So rather than "select p" or "select new Parent()" we let the static function return "p" but also assign the Child object to "parent.Child" before returning. As long as your associations are setup properly (BLToolkit.Mapping.Association) p.Child would tell BLT to join to the Child table as well. You could go even further, i.e. p.Child.Friends.etc.