LINQ IS NULL

by iatanasov 26. February 2008 15:42

category.ParentCategoryId = @parentCategoryId

 or

category.ParentCategoryId = null and this sql didn't return result, because expect category.ParentCategoryId is null.

Then I test another way to delive null value 

 if (parentCategoryId == null)
            {
                var query = from
                                    category in this.productsHelpDataContext.Categories
                            orderby
                                    category.Order ascending
                            where
                                category.ParentCategoryId == null

                            select category;

                return query.Select(category => category);
            }
            else
            {
                var query = from
                                    category in this.productsHelpDataContext.Categories
                            orderby
                                    category.Order ascending
                            where
                                category.ParentCategoryId == parentCategoryId
                            select category;

                return query.Select(category => category);
            }

In other word LINQ to SQL strict follow sql script convention.

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

MS SQL

Related posts

Comments

March 22. 2008 15:39

Gravatar

useful post for null data types

anderson us

Add comment


(Will show your Gravatar icon)  

  Country flag




Live preview

July 6. 2008 05:29

Gravatar

Powered by BlogEngine.NET 1.1.0.7
Theme by Mads Kristensen

About the author

Ivan Atanasov - web developer
E-mail me Send mail Subscribe Feed

Calendar

<<  July 2008  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Authors

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008 it-coder.com

    Sign in