请将这个 LINQ C# 转换为 VB

发布于 2024-10-25 23:21:27 字数 1055 浏览 1 评论 0原文

你好 我在网上找到了这段代码,但无法将其转换为 vb。 如果有人帮我将此 LINQ C# 代码转换为 VB,我将非常感激。 这是代码:

/// <summary>
/// 
/// </summary>
/// <returns></returns>
[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable<Customer> FindByID(string id)
{
    //  find the customer
    return (from c in this.Customers where c.ID == id select c).ToList();
}

/// <summary>
/// 
/// </summary>
/// <param name="customer"></param>
public void Update(Customer newValues)
{
    //  simulate putting this record back into the database
    Customer oldValues = this.Customers.Find(x => x.ID == newValues.ID);

    oldValues.CompanyName = newValues.CompanyName;
    oldValues.ContactName = newValues.ContactName;
    oldValues.ContactTitle = newValues.ContactTitle;
    oldValues.Address = newValues.Address;
    oldValues.City = newValues.City;
    oldValues.State = newValues.State;
    oldValues.ZIPCode = newValues.ZIPCode;
    oldValues.Phone = newValues.Phone;
}

}

非常感谢您为我做这件事。 马特

Hi
I found this code on line and cannot convert it over to vb.
I would really appreciate it if someone would convert this LINQ C# code to VB for me.
Here is the code:

/// <summary>
/// 
/// </summary>
/// <returns></returns>
[DataObjectMethod(DataObjectMethodType.Select)]
public IEnumerable<Customer> FindByID(string id)
{
    //  find the customer
    return (from c in this.Customers where c.ID == id select c).ToList();
}

/// <summary>
/// 
/// </summary>
/// <param name="customer"></param>
public void Update(Customer newValues)
{
    //  simulate putting this record back into the database
    Customer oldValues = this.Customers.Find(x => x.ID == newValues.ID);

    oldValues.CompanyName = newValues.CompanyName;
    oldValues.ContactName = newValues.ContactName;
    oldValues.ContactTitle = newValues.ContactTitle;
    oldValues.Address = newValues.Address;
    oldValues.City = newValues.City;
    oldValues.State = newValues.State;
    oldValues.ZIPCode = newValues.ZIPCode;
    oldValues.Phone = newValues.Phone;
}

}

Thank you soo much for doing this for me.
Matt

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜还是长夜 2024-11-01 23:21:27

您应该能够使用:

<DataObjectMethod(DataObjectMethodType.[Select])> _
Public Function FindByID(id As String) As IEnumerable(Of Customer)
    '  find the customer
    Return (From c In Me.Customers Where c.ID = idc).ToList()
End Function

Public Sub Update(newValues As Customer)

    '  simulate putting this record back into the database
    Dim oldValues As Customer = Me.Customers.Find(Function(x) x.ID = newValues.ID)

    oldValues.CompanyName = newValues.CompanyName
    oldValues.ContactName = newValues.ContactName
    oldValues.ContactTitle = newValues.ContactTitle
    oldValues.Address = newValues.Address
    oldValues.City = newValues.City
    oldValues.State = newValues.State
    oldValues.ZIPCode = newValues.ZIPCode
    oldValues.Phone = newValues.Phone
End Sub

You should be able to use:

<DataObjectMethod(DataObjectMethodType.[Select])> _
Public Function FindByID(id As String) As IEnumerable(Of Customer)
    '  find the customer
    Return (From c In Me.Customers Where c.ID = idc).ToList()
End Function

Public Sub Update(newValues As Customer)

    '  simulate putting this record back into the database
    Dim oldValues As Customer = Me.Customers.Find(Function(x) x.ID = newValues.ID)

    oldValues.CompanyName = newValues.CompanyName
    oldValues.ContactName = newValues.ContactName
    oldValues.ContactTitle = newValues.ContactTitle
    oldValues.Address = newValues.Address
    oldValues.City = newValues.City
    oldValues.State = newValues.State
    oldValues.ZIPCode = newValues.ZIPCode
    oldValues.Phone = newValues.Phone
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文