Wednesday, February 10, 2021

Backend best practices

 Select praticulr coloms from database (EF)


https://git.itelasoft.com.au/chamith.saranga/broker-service/blob/master/Application/Services/BankStatementService.cs#L544

return await DataContext.BankStatements
                .Where(s => bankStatementIds.Contains(s.RequestId))
                .Include(s => s.Applicant).Include(s => s.Lender)
                .Select(m => new BankStatementModel
                {
                    RequestId = m.RequestId,
                    ApplicantId = m.ApplicantId,
                    ApplicantName = $"{m.Applicant.FirstName} {m.Applicant.LastName}",
                    IsPrimaryApplicant = m.Applicant.PrimaryApplicant,
                    LenderId = m.LenderId,
                    LenderName = m.Lender != null?m.Lender.Name : m.LenderName,
                    LenderLogo = m.Lender.Logo,
                    Deprecated = m.Deprecated,
                    Provider = m.Provider,
                    RequestVersion = m.RequestVersion
                }).ToListAsync();

EF.Function
https://git.itelasoft.com.au/chamith.saranga/broker-service/blob/master/Application/Services/ProductService.cs#L134
           if (!string.IsNullOrWhiteSpace(name))           
                query = query
                    .Where(p => EF.Functions.Like(p.Name, $@"%{name}%"));          

No comments:

Post a Comment

CS Events