ObjectDataSource 和 LINQ 技术细节
我有一个关于 LINQ 的小问题。
我有一个类别集合(大约 100 个)。其中一些是其他类别的孩子。这是此类型的 IList
:
public Guid TempID { get; set; }
public Nullable<int> ID { get; set; }
public bool Published { get; set; }
public int CategoryLevel { get; set; }
public int CategoryOrder { get; set; }
public DateTime UpdatedDate { get; set; }
public Nullable<int> RefParent { get; set; }
public bool GotChildren { get; set; }
如果我想在 DataList
(可能是 DataList
)中表示此类型,最好的方法是什么code>DataList、DataList
等)使用 ASP.net。另一个技术问题是孩子的数量不是静态的。我们目前有 3 个深度,但很容易有 5 个。
必须说我无法更改数据返回的位置和方式,因为它是来自外部 API 的方式。我要做的就是向他们展示。
谢谢您,请随时向我询问更多详细信息。我来自魁北克,通常说法语,所以也许我的英语不是很好。
编辑
必须告诉我,我知道如何对 DataList 进行数据绑定。我的问题实际上是如何将数据列表的数据列表(并且不知道深度)数据绑定到包含所有级别的简单维度列表。是否可以?
I've a little question on LINQ.
I have a collection of categories (about 100). Some of them are children of another category. This is an IList
of this type:
public Guid TempID { get; set; }
public Nullable<int> ID { get; set; }
public bool Published { get; set; }
public int CategoryLevel { get; set; }
public int CategoryOrder { get; set; }
public DateTime UpdatedDate { get; set; }
public Nullable<int> RefParent { get; set; }
public bool GotChildren { get; set; }
What is the best approach if I want to represent this type in a DataList
(potentially a DataList
of DataList
, of DataList
, etc) using ASP.net. Another technicality is that the number of children is not static. We presently have 3 depth but it can easly have 5.
Must say that I can't change where and how data are return because it's how it comes from an external API. What I've to do, it's simply showing them.
Thank you, and feel free to ask me more details. I'm from quebec and usualy talk french so maybe me english is not very good.
Edit
Must tell that I know how to databind the DataList. My problem is realy how can I DataBind a datalist of datalist (and don't know the depth) to a Simple dimension list that contains all level. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了子孙后代......
列表<类别>类别
应该没问题。属性通过以下方式公开:您可以针对集合运行 LINQ:
UPDATE_3:
好的,我现在明白了 - 您收到一个如下所示的对象:
...并且您需要能够添加集合子类别?
如果您无法继承该类,我将通过以下方式使用该对象:
...在外部,调用:
更新该方法以与 Dictionary.TryGetValue() 类似的方式工作;
UPDATE_2:
您需要向您的类型添加集合(
ICollection
、List
等)属性:这将添加无限的深度。我不明白为什么不能使用 DataList 作为您的 SubItems 数据类型。
更新:
仔细查看 DataList 类后,您必须使用
ICollection
作为数据源。 MSDN 显示List
继承自ICollection
&ICollection
。IList
继承自ICollection
;而IList
继承自ICollection
。MSDN 还有示例 。
for posterity's sake...
List<Category> categories
should be fine. Properties are exposed via something like :You can run LINQ against the collection:
UPDATE_3:
Okay, I understand now - you receive an object that looks like:
...and you need to be able to add collections of child categories?
If you cannot inherit the class, I would consume the object by:
...externally, call:
Updated the method to work in similar fashion to Dictionary.TryGetValue();
UPDATE_2:
You will need to add a collection (
ICollection
,List<T>
, etc.) property to your type:This will add unlimited depth. I don't see why couldn't use the DataList as your SubItems data type.
UPDATE:
After looking at the DataList class more carefully, you must use an
ICollection
as the DataSource. MSDN shows thatList<T>
inherits fromICollection
&ICollection<T>
.IList
inherits fromICollection
; whileIList<T>
inherits fromICollection<T>
.MSDN also has a sample.