枚举“列”在实体框架中

发布于 2024-10-10 03:12:57 字数 1574 浏览 2 评论 0原文

我们正在尝试 EF4,但遇到了困难。

我们有一个管理会员数据的应用程序,核心要求是使用 Word 邮件合并生成信件。

在当前的实现中,我们为所需记录生成一个数据集,并枚举它的列和行以创建一个制表符分隔的文本文件,Word 可以使用该文件进行合并。 (这非常有效,使用 Tab 是因为文件中有多行结果,例如 FormattedAddressBlock)。

对于 EF4,无法在内部转换为数据集(此功能在 Orcas beta 后被删除),所以问题是:

我们如何枚举 LINQ 或 ObjectQuery 的列和行以允许我们构建文本文件。

这是我们与数据表一起使用的代码示例。

    Using wmTextWriter As TextWriter = New StreamWriter(WordMergeDataFile)

        ' Write the header row to the merge data file.
        Dim wmOutput As New StringBuilder()
        For i As Integer = 0 To MergeData.Columns.Count - 1
            wmOutput.Append(MergeData.Columns(i).ColumnName & vbTab)
        Next
        wmOutput.Remove(wmOutput.Length - 1, 1) ' Remove the trailing Tab character.
        wmTextWriter.WriteLine(wmOutput.ToString)

        ' Loop through the datatable and write out the data rows to the work merge file.
        wmOutput = New StringBuilder()
        With MergeData
            For iRowNo As Integer = 0 To .Rows.Count - 1
                For iColNo As Integer = 0 To .Columns.Count - 1
                    wmOutput.Append(DOUBLEQUOTE & .Rows(iRowNo).Item(iColNo).ToString & DOUBLEQUOTE & vbTab)
                Next
                wmOutput.Remove(wmOutput.Length - 1, 1) ' Remove the trailing Tab character.
                wmTextWriter.WriteLine(wmOutput.ToString)
                wmOutput = New StringBuilder()
            Next
        End With

        wmOutput = Nothing
        wmTextWriter.Close()

    End Using

任何帮助将不胜感激。

马克·哈比 诺丁汉。英国

we are dipping our toes with EF4 and have hit a wall.

We have an application that manages member data and a core requirement is to generate letters using Word mail merge.

In the current implementation we generate a dataset for the required records and enumerate it's columns and rows to create a tab delimited text file that Word can use to merge from. (This works really well, the Tab is used as there are multi-line results in the file such as FormattedAddressBlock).

With EF4 there is no way to convert internally to a dataset (this feature was dropped after the Orcas beta), so to the question:

How do we enumerate the columns and rows of a LINQ or ObjectQuery to allow us to build the text file.

Here is a sample of code we use with the datatable.

    Using wmTextWriter As TextWriter = New StreamWriter(WordMergeDataFile)

        ' Write the header row to the merge data file.
        Dim wmOutput As New StringBuilder()
        For i As Integer = 0 To MergeData.Columns.Count - 1
            wmOutput.Append(MergeData.Columns(i).ColumnName & vbTab)
        Next
        wmOutput.Remove(wmOutput.Length - 1, 1) ' Remove the trailing Tab character.
        wmTextWriter.WriteLine(wmOutput.ToString)

        ' Loop through the datatable and write out the data rows to the work merge file.
        wmOutput = New StringBuilder()
        With MergeData
            For iRowNo As Integer = 0 To .Rows.Count - 1
                For iColNo As Integer = 0 To .Columns.Count - 1
                    wmOutput.Append(DOUBLEQUOTE & .Rows(iRowNo).Item(iColNo).ToString & DOUBLEQUOTE & vbTab)
                Next
                wmOutput.Remove(wmOutput.Length - 1, 1) ' Remove the trailing Tab character.
                wmTextWriter.WriteLine(wmOutput.ToString)
                wmOutput = New StringBuilder()
            Next
        End With

        wmOutput = Nothing
        wmTextWriter.Close()

    End Using

Any help would be much appreciated.

Mark Harby
Nottingham. UK

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文