如何将关系数据集转换为嵌套的ObservableCollection? [英] How would I convert a relational dataset to a nested ObservableCollection?
问题描述
我现在卡住了。我有一个包含2个相关表的数据集。它是一个简单的父表,带有一个相关的子表。
由于各种原因,我需要将数据集转换为嵌套的ObservableCollection。以下Linq代码适用于1个问题:我在嵌套集合中缺少where子句,因此所有子节点都是父节点的一部分是不正确的。
I''m stuck at the moment. I have a dataset with 2 related tables. It''s a simple parent table with a single related child table.
For various reasons, I need to convert the dataset into a nested ObservableCollection. The following Linq code works with 1 issue: I''m missing a where clause on the nested collection so all of the children are part of the parent which is incorrect.
this.ocApps = new ObservableCollection<Models.ApplicationTypesModel>(this.dsApps.tAppTypes.AsEnumerable().Select(apptype => new Models.ApplicationTypesModel
{
AppType = apptype.nvarAppType,
Apps=new ObservableCollection<Models.ApplicationModel>(this.dsApps.tApps.AsEnumerable().Select(apps=>new Models.ApplicationModel
{
idAppId=apps.idAppId,
strAppName=apps.nvarAppName,
strEnvironment=apps.nvarEnvironment,
strAppType=apps.nvarAppType,
dtLastPrivACCertDate= apps.dtLastPrivACCertDt
}).where(the parent table.apptype value = the child table.apptype value))
}));
我想我需要在内部选择的位置,这是有道理的...但我不知道在哪里或如何把它放在哪里。
有没有人有一些建议?
谢谢
I think I need a where on the inner select, which makes sense...but I''m not sure where or how to put the where.
Does anyone have some suggestions?
Thanks
推荐答案
这完美无缺。 where的语法是我所缺少的。以下URL可能对需要将关系数据集转换为嵌套ObservableCollection的其他人有所帮助。我的意图是使用这个特定应用程序的MVVM模式的ViewModel。
http://stackoverflow.com/questions/6359980/proper-linq-where-clauses
格式})。其中(app => app.strAppType == apptype.nvarAppType)是扔我的东西。
This works perfectly. The syntax of the "where" is what I was missing. The following URL may be of help to someone else who needs to convert a relational dataset to a nested ObservableCollection. My intent is in the ViewModel of a MVVM pattern with this particular app.
http://stackoverflow.com/questions/6359980/proper-linq-where-clauses
The format of "}).Where(app=>app.strAppType==apptype.nvarAppType)" is what was throwing me.
this.ocApps = new System.Collections.ObjectModel.ObservableCollection<Models.ApplicationTypesModel>(this.dsApps.tAppTypes.AsEnumerable().Select(apptype => new Models.ApplicationTypesModel
{
AppType = apptype.nvarAppType,
Apps = new System.Collections.ObjectModel.ObservableCollection<Models.ApplicationModel>(this.dsApps.tApps.AsEnumerable().Select(apps => new Models.ApplicationModel
{
idAppId = apps.idAppId,
strAppName = apps.nvarAppName,
strEnvironment = apps.nvarEnvironment,
strAppType = apps.nvarAppType,
dtLastPrivACCertDate = apps.dtLastPrivACCertDt
}).Where(app=>app.strAppType==apptype.nvarAppType))
}));
这篇关于如何将关系数据集转换为嵌套的ObservableCollection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!