使用linq的NHibernate递归查询

编程入门 行业动态 更新时间:2024-10-27 00:27:50
本文介绍了使用linq的NHibernate递归查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好. 假设我的桌子上有菜单项.每个项目都有其父项的ID和ID.斯坦达特.如何在不使用字符串sql和后处理(即.ToList().AsHierarchy())的情况下使用linq选择树(列表中或其他列表中的列表)?

Hello. Let''s say I have table with menu items. Each item have id and id of it''s parent. Standart. How can I select tree (list in list or smth else) using linq without string sql and post-processing (i.e. .ToList().AsHierarchy())? Is that possible?

推荐答案

您应该将子列表映射到菜单项类.这样,菜单项的每个实例还包含其子级,您可以轻松地对其进行迭代.您要做的就是选择ParentId = 0的菜单项. MenuItem-class: You should map a list of children to a menu item class. That way each instance of a menu item also contains its children and you can easily iterate them. All you have to do is to select menu items where ParentId=0. MenuItem-class: [Bag(0, Name = "Children", Inverse = true, Lazy = CollectionLazy.False)] [Key(1, Column = "MenuItemParentId")] [OneToMany(2, ClassType = typeof(MenuItem))] public virtual IList<menuitem> Children { get { return _children; } set { _children = value; } } </menuitem>

或通过xml映射(不过,类中仍必须具有Children属性):

Or by xml mapping (must still have the Children property in the class, though):

<bag name="Children" lazy="false" inverse="true"> <key column="MenuItemParentId" /> <one-to-many class="Your.Namespace.MenuItemParentId, Your.Namespace" /> </bag>

更多推荐

使用linq的NHibernate递归查询

本文发布于:2023-05-26 16:20:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/265213.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   linq   NHibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!