Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
cast to decimal in linq query
var data = await dbContext.Set<OwnerData>().FromSqlRaw(@"
                SELECT [OWP].[OwnerProfileId],                    
                SELECT [OWP].[Email],
                FROM [user].[OwnerProfile] AS [OWP]
                CAST(ISNULL([OWB].[CustomBalance], 0) AS decimal(18, 3)) AS [CustomBalance]
                INNER JOIN [user].[OwnerBalance] AS [OWB] ON [OWB].[OwnerProfileId] = [OWP].[OwnerProfileId]
                WHERE [ThirdPartyRefId] = {0}", ownerProfileId)
               .ToListAsync();

I rewrite this into linq expression like this

 var data = await _context.Set<OwnerProfile>()
                .Include(x => x.OwnerBalances)                
                .Where(x => x.ThirdPartyRefId== ownerProfileId)
                .ToListAsync();

not sure how to set this

CAST(ISNULL([OWB].[CustomBalance], 0) AS decimal(18, 3)) AS [CustomBalance]

into lambda query

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Without having class definitions its a little difficult to give you specifics, but you could try to add something like:

var data = await _context.Set<OwnerProfile>()
                .Include(x => x.OwnerBalances)                
                .Where(x => x.ThirdPartyRefId== ownerProfileId)
                .Select(x => new 
                 {
                    x.Prop1,
                    x.Prop2,
                    CustomerBalance = x.CustomerBalance.Value != null ? x.CustomerBalance.Value : 0
                 })
                .ToListAsync();

You may be able to move the select statement outside the query too:

var newData = data.Select(x => new 
              {
                 x.Prop1,
                 x.Prop2,
                 CustomerBalance = x.CustomerBalance.Value != null ? x.CustomerBalance.Value : 0
              })

You might be able to use conditional access in the 2nd version, but possibly not in the first.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!