none
LINQ to SQL IsNull RRS feed

  • Question

  • How can i reproduce this in LINQ to SQL?

     

    ColumnName is a decimal(10,2) datatype.

     

    Code Snippet

    SELECT

    SUM(ISNULL(ColumnName, 0)) AS TotalColumnName

    FROM

    TableName

     

     

     

    Friday, June 20, 2008 4:12 PM

Answers

  • Something along the lines of the following would work:

     

    Code Snippet
         decimal total = db.TableName.Sum(o => o.ColumnName ?? 0);

     

     

    Hope that helps,

     

    Thanks,

    --Samir

     

    Friday, June 20, 2008 4:30 PM

All replies

  • Something along the lines of the following would work:

     

    Code Snippet
         decimal total = db.TableName.Sum(o => o.ColumnName ?? 0);

     

     

    Hope that helps,

     

    Thanks,

    --Samir

     

    Friday, June 20, 2008 4:30 PM
  •  

    Thank you!
    Friday, June 20, 2008 4:33 PM
  • How do I achieve this in Linq to EF

    isnull(bb.ID,'') = isnull(@Branch_ID,isnull(bb.ID,''))


    Software Developer
    Tuesday, June 15, 2010 7:24 PM