Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在linq中跳过列表中的一列(可能更多)数据_C#_Linq_Generic List_Linq To Excel - Fatal编程技术网

C# 如何在linq中跳过列表中的一列(可能更多)数据

C# 如何在linq中跳过列表中的一列(可能更多)数据,c#,linq,generic-list,linq-to-excel,C#,Linq,Generic List,Linq To Excel,我正在使用LINQtoExcel将两个excel工作表中的输入读取到两个列表中。其中一个工作表中有一列不需要的数据,该列的名称为“已知”。但是,两个工作表中的其他列包含完全相同类型的数据。 我的问题的第一部分是: 如何在select语句中仅排除未安装的数据列,而不必为其他25列写入select.column名称?我打算这样做的目的如下: 使两个列表的类型相同 合并两个列表 可能会将这段代码移到调用过程中,因为最终我将不得不阅读更多的工作表 ExcelQueryFactory excel = ne

我正在使用LINQtoExcel将两个excel工作表中的输入读取到两个列表中。其中一个工作表中有一列不需要的数据,该列的名称为“已知”。但是,两个工作表中的其他列包含完全相同类型的数据。 我的问题的第一部分是: 如何在select语句中仅排除未安装的数据列,而不必为其他25列写入select.column名称?我打算这样做的目的如下:

使两个列表的类型相同 合并两个列表 可能会将这段代码移到调用过程中,因为最终我将不得不阅读更多的工作表

ExcelQueryFactory excel = new ExcelQueryFactory(FilePath);
List<STC> stResults = (from s
                       in excel.Worksheet<STC>("StaticResults")
                       select s)
                       .ToList();

List<DYN> dynResults = (from s
                        in excel.Worksheet<DYN>("DynamicResults")
                        select s)      //how can I EXCLUDE just one of the columns here??
                        .ToList();
我是c和linq的新手。所以请原谅我的无知:-

我问题的第二部分是: 我提取的上述数据有点偏胖,从100000行到300000行不等。我必须使用for循环,在1000到4000次的范围内,对上面的列表重复进行linq查询。有没有更好的方法来实现这一点,因为它会对性能造成巨大损失

编辑_1: 关于输入文件:

StaticResults文件有28列STC类有28个属性 DynamicResults文件有29列,28列具有与static相同的属性/列名,另外还有一个属性,这不是必需的。DYN是STC的派生类
从linq选择结果时使用匿名类型

ExcelQueryFactory excel = new ExcelQueryFactory(FilePath);
List<STC> stResults = (from s
                       in excel.Worksheet<STC>("StaticResults")
                       select s)
                       .ToList();

List<DYN> dynResults = (from s
                        in excel.Worksheet<DYN>("DynamicResults")
                        select new {Property1 = s.xxx, Property2 = S.yyy)      //get the props based on the type of S
                        .ToList();
意外地想出了我第一个问题的答案。也许没有什么了不起的,但是我想在这里分享一下

摆脱了二等兵DYN 第二个列表是STC类型
这样,生成的两个列表都只提取在所属类中声明的必需属性/列。不需要的额外列被跳过,因为我没有在类中将这些列定义为属性。我想这是linq对excel的礼遇。如果有人能更深入地了解这一点,我想了解更多。

有25个以上的属性,我希望避免在select语句中写入所有25个属性。并不是说我懒惰,而是我懒惰!!但我只是想知道是否有更好的方法。非常感谢您的及时回复:-