Linq to Entities写入文件流或文本文件 [英] Linq to Entities write to Filestream or Text File

查看:59
本文介绍了Linq to Entities写入文件流或文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不使用For Each循环将结果集写入文本文件.是否有更快,更有效的方式将Linq传输到实体或将Linq传输到对象?

I would like to write my result set to a text file without using a For Each Loop. Is there a quicker more efficient way to stream Linq to Entities or Linq to Objects?

推荐答案

我要假设您需要将IEnumerable(Of String)存储到用逗号分隔的文件.使用Aggregate扩展可以相当直接地做到这一点.


I am going to assume you need to store an IEnumerable(Of String) into a file separated by comma. This can be done fairly directly using the Aggregate extension.


' We need to write the IEnumerable(Of String) SourceCollection into the text file "Numbers.txt"
        My.Computer.FileSystem.WriteAllText("numbers.txt", SourceCollection.Aggregate(Function(item, aggregator) String.Format("{1},{0}", aggregator, item)), False)


这篇关于Linq to Entities写入文件流或文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆