ASP.Net: Convert LINQ query from C# to VB.Net

ezrawy
 
on Apr 04, 2022 10:47 PM
1030 Views

I have C# class when converting to VB become with error

The C# class

private void Getbanks(int projectId)
{
 using (UniFinancials_dbEntities uniFinancials_dbEntities = new UniFinancials_dbEntities())
 {
     List<int> bankId;
     if (BaseGlobals.UserProfile.UserEntity.GroupId == 2)
     {
         bankId = (from x in uniFinancials_dbEntities.FV_EmpCoordinatorBank
             where x.EmpId == BaseGlobals.UserProfile.UserEntity.EmpId
             select x into s
             select s.BankId).ToList();
     }
     else
     {
         bankId = (from x in uniFinancials_dbEntities.BanksAndProjects
             where x.ProjectId == projectId
             select x into s
             select s.BankId).ToList();
     }
     List<BankInformations> dataSource = (from x in uniFinancials_dbEntities.Banks
         where bankId.Contains(x.BankId)
         select x into bank
         select new BankInformations
         {
             BankId = bank.BankId,
             DomainName = bank.DomainName,
             BankName = bank.BankName,
             Logo = bank.Logo,
             Extension = bank.Extension,
             BranchName = bank.BranchName,
             Address = bank.Address,
             Addedby = bank.Addedby,
             AddedDate = bank.AddedDate,
             FV_EmpCoordinatorBank = bank.FV_EmpCoordinatorBank.ToList()
         }).ToList();
     Repeater_Banks.DataSource = dataSource;
     Repeater_Banks.DataBind();
 }

I convert with telerik and Code Converter VB - C# online

Private Sub Getbanks(ByVal projectId As Integer)
    Using uniFinancials_dbEntities As UniFinancials_dbEntities = New UniFinancials_dbEntities()
        Dim bankId As List(Of Integer)
 
        If BaseGlobals.UserProfile.UserEntity.GroupId = 2 Then
            bankId = (From x In uniFinancials_dbEntities.FV_EmpCoordinatorBank Where x.EmpId = BaseGlobals.UserProfile.UserEntity.EmpId Select x).ToList()
        Else
            bankId = (From x In uniFinancials_dbEntities.BanksAndProjects Where x.ProjectId = projectId Select x).ToList()
        End If
 
        Dim dataSource As List(Of BankInformations) = (From x In uniFinancials_dbEntities.Banks Where bankId.Contains(x.BankId) Select x).ToList()
        Repeater_Banks.DataSource = dataSource
        Repeater_Banks.DataBind()
    End Using
End Sub

When converting from c# to vb the code have parts messing like that example

List<FV_CustomersAddresses> list3 = (from x in uniFinancials_dbEntities.FV_CustomersBasicInfo
                                     where x.CaseDateStarted <= DbFunctions.TruncateTime(DateTime.Now) && x.CaseDateEnded >= DbFunctions.TruncateTime(DateTime.Now) && x.FV_BanksLoansType.InquiryTypeId == item.InquiryTypeId
                                     select x into all
                                     join address in from x in uniFinancials_dbEntities.FV_CustomersAddresses
                                     where x.EmpId == (int?)hfEmpId
                                     select x on all.CustomerId equals address.CustomerId
                                     select address).ToList();

 

Dim list3 As List(Of FV_CustomersAddresses) = (From x In uniFinancials_dbEntities.FV_CustomersBasicInfo Where x.CaseDateStarted <= DbFunctions.TruncateTime(DateTime.Now) AndAlso x.CaseDateEnded >= DbFunctions.TruncateTime(DateTime.Now) AndAlso x.FV_BanksLoansType.InquiryTypeId = item.InquiryTypeId Select x).ToList()

in vb code the part of

join address in from x in uniFinancials_dbEntities.FV_CustomersAddresses

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Apr 11, 2022 12:00 AM

Refer below query.

Dim list3 As List(Of FV_CustomersAddresses) = (From x In uniFinancials_dbEntities.FV_CustomersBasicInfo
                                                Join address In uniFinancials_dbEntities.FV_CustomersAddresses
                                                    On x.CustomerId Equals address.CustomerId
                                                Where x.CaseDateStarted <= DbFunctions.TruncateTime(DateTime.Now) _
                                                    AndAlso x.CaseDateEnded >= DbFunctions.TruncateTime(DateTime.Now) _
                                                    AndAlso x.FV_BanksLoansType.InquiryTypeId = item.InquiryTypeId _
                                                    AndAlso x.EmpId == CType(hfEmpId, Integer?)
                                                Select address).ToList()