I'm trying to convert this vb.net code to c#.
If (txtCompanyName.Text.Trim() <> String.Empty) Then
decals = decals.Where(Function(d As CT_Decal) (From c In db.CT_Companies Where c.CompanyName.Contains(txtCompanyName.Text.Trim()) Select c.CompanyID).ToList.Contains((From t In db.CT_Tanks Where t.CargoTankID = d.TankID Select t.CompanyID).Single.ToString()))
End If
In c# I tried to put the code:
if (txtCompanyName.Text.Trim() != string.Empty)
{
decals = decals.Where(Function(CT_Decal d)(from c in db.CT_Companies
where c.CompanyName.Contains(txtCompanyName.Text.Trim())
select c.CompanyID).ToList().Contains((from t in db.CT_Tanks where t.CargoTankID == d.TankID
select t.CompanyID).Single.ToString()));
}//end if
c# errors:
The name function does not exist and CT_Decal is a type but is used like a variable.
Does anybody know how to convert this properly?
!String.IsNullOrEmpty(txtCompanyName.Text)instead oftxtCompanyName.Text.Trim() != string.EmptyToList()is redundant and the code shouldn’t compile in VB sinceWhereexpects a predicate but your lambda is returning a string.IsNullOrWhiteSpaceright