帮助将C#转换为VB,使用转换工具获取错误。 [英] Help converting C# to VB getting errors with conversion tool.

查看:101
本文介绍了帮助将C#转换为VB,使用转换工具获取错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下正在编写的C#代码,但我也需要在VB应用程序中使用它。



I have the following working C# code which I have written but need to use it in a VB app as well.

public IQueryable<Employee> LoadEmployee()
{

    using (DbConnection connection = GetConnection())
    {
        using (DbCommand command = connection.CreateCommand())
        {

            command.CommandText = "[HR].[usp_Employee]";
            command.CommandType = CommandType.StoredProcedure;

            connection.Open();

            using (DbDataReader reader = command.ExecuteReader())
            {
                DataTable table = new DataTable();

                table.Load(reader);

                return (from employee in table.AsEnumerable()
                        select new
                        {
                            EmployeeName = employee.Field<string>("EmployeeName")

                        }).Select(model => new Entity

                        {
                            EmployeeName = model.EmployeeName

                        }).AsQueryable();
            }
        }
    }
}





我尝试了什么:



我尝试了几种转换工具但却遇到了多个错误:



以下是转换工具的示例:





What I have tried:

I have tried several conversion tools but getting multiple errors:

Here is a sample from a conversion tool:

Public Function LoadEmployee() As IQueryable(Of Employee)

    Using connection As DbConnection = GetConnection()
        Using command As DbCommand = connection.CreateCommand()

            command.CommandText = "[HR].[usp_Employee]"
            command.CommandType = CommandType.StoredProcedure

            connection.Open()

            Using reader As DbDataReader = command.ExecuteReader()
                Dim table As New DataTable()

                table.Load(reader)

            Return (From employee In table.AsEnumerable()New With { _
                Key .EmployeeName = employee.Field(Of String)("EmployeeName") _
            }).[Select](Function(model) New Entity() With { _
                Key .EmployeeName = model.EmployeeName _
            }).AsQueryable()
            End Using
        End Using
    End Using
End Function

推荐答案

看起来像 Telerik Code Converter [ ^ ]输出。我认为更正是:

That looks like Telerik Code Converter[^] output. I think that the correction is:
Public Function LoadEmployee() As IQueryable(Of Employee)

    Using connection As DbConnection = GetConnection()
        Using command As DbCommand = connection.CreateCommand()

            command.CommandText = "[HR].[usp_Employee]"
            command.CommandType = CommandType.StoredProcedure

            connection.Open()

            Using reader As DbDataReader = command.ExecuteReader()
                Dim table As New DataTable()

                table.Load(reader)

                Return (From employee In table.AsEnumerable()
                        Select New With
                        {.EmployeeName = employee.Field(Of String)("EmployeeName")}) _
                    .Select(Function(model) New Entity() With
                        {.EmployeeName = model.EmployeeName}) _
                    .AsQueryable()
            End Using
        End Using
    End Using
End Function


这篇关于帮助将C#转换为VB,使用转换工具获取错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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