0
CHV1 CDD1                                               CHV2 CDD2                                               CHV3 CDD3                                               CHV4        CDD4                                                                                                                           SortCol                                                                                                                        SearchColCount
---- -------------------------------------------------- ---- -------------------------------------------------- ---- -------------------------------------------------- ----------- ------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------ --------------

 Adventure Cafe Columbus                                 Back Of The House                                       Cook                                               624         Adams, Donald, 4180259, A                                                                                                      A, Adams, Donald, 4180259                                                                                                      0
 Adventure Cafe Columbus                                 Back Of The House                                       Cook                                               643         Conard, Virgil, 4180469, A                                                                                                     A, Conard, Virgil, 4180469                                                                                                     0
 Adventure Cafe Columbus                                 Back Of The House                                       Cook                                               629         Pheiffer, Seth, 4180373, A                                                                                                     A, Pheiffer, Seth, 4180373                                                                                                     0
 Adventure Cafe Columbus                                 Back Of The House                                       Cook                                               645         Sees, Patrick, 4180474, A                                                                                                      A, Sees, Patrick, 4180474                                                                                                      0
 Adventure Cafe Columbus                                 Back Of The House                                       Cook                                               657         Walter, Derek, 4180508, A                                                                                                      A, Walter, Derek, 4180508                                                                                                      0

The above is the dataset from the DB.

I am trying to use LINQ to take a dataset and create a custom object type, based on the above data structure, but one of the members of that object is a List data type.

I originally found the following article, but it wasn't working exactly, since it was a simple string List object type: Convert Datatable to Object with Linq and Group by This is giving me the following error:

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.List'. An explicit conversion exists (are you missing a cast?)

I have listed my adaptation to the code from the above referenced article. Ideally, I would like to be able to dynamically create multiple "folderItem" Lists based on CDD2, CDD3, CDD4, etc... The number of CDD columns would be variable, which further complicated things.

This data will ultimately be return from a WCF service as JSON.

dnFolders = from row in dnDataTable.AsEnumerable()
    group row by new
    {
        id = row.Field<string>(1),
        value = row.Field<string>(2)

    } into folder
    select new folder
    {
        id = folder.Key.id,
        value = folder.Key.value
        folderItem = section.Select(r=>r.Field<String>(3)).ToList()
    };

folder class definition:

public class folder
{
    [DataMember(Name = "id", Order = 1)]
    public string id { get; set; }

    [DataMember(Name = "value", Order = 2)]
    public string value { get; set; }

    [DataMember(Name = "type", Order = 3)]
    public string type { get; set; }

    [DataMember(Name = "sortCol", Order = 4)]
    public string sortCol { get; set; }

    [DataMember(Name = "folderItems", Order = 5)]
    public List<folderItem> folderItems { get; set; }
}

folderItem class definition

public class folderItem
{
    [DataMember(Name = "value", Order = 1)]
    public string value { get; set; }

    [DataMember(Name = "id", Order = 2)]
    public string id { get; set; }

    [DataMember(Name = "type", Order = 2)]
    public string type { get; set; }
}

Determine that the languages accepted by two NFA's are same or not

I have two NFA's. I need to determine whether both recognize the same language I would be much obliged if anyone could be so kind enough to explain how to do this.

4

2 回答 2

1

也许来自lazyberezovsky的回答的一些调整

我相信您的错误来自您的 dnFolders 变量是 List 吗?在这种情况下,您必须 .ToList() 整个查询

dnFolders = 
    (from row in dnDataTable.AsEnumerable()
    group row by new
    {
        id = row.Field<string>(1),
        value = row.Field<string>(2)
    } into g
    select new folder
    {
        id = g.Key.id,
        value = g.Key.value
        folderItems = g.Select(r => r.Field<FolderItems>(5) })
                       .ToList()
    }).ToList();
于 2013-04-20T10:19:22.417 回答
0

您的查询中有几个问题:

  • 没有section定义变量
  • 类中没有folderItem属性folder
  • 您应该folderItem从每个组中选择对象列表,但您选择的是字符串列表

这是您的查询应该是什么样子(我不知道应该去folderItem对象,所以type只用属性初始化它):

dnFolders = 
    from row in dnDataTable.AsEnumerable()
    group row by new
    {
        id = row.Field<string>(1),
        value = row.Field<string>(2)
    } into g
    select new folder
    {
        id = g.Key.id,
        value = g.Key.value
        folderItems = g.Select(r => new folderItem { type = r.Field<string>(3) })
                       .ToList()
    };
于 2013-04-20T10:02:04.857 回答