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 newVal开发者_StackOverflow中文版ues)
{
// 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
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
精彩评论