If From & To date is same record not filtering LINQ



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am filtering records based on Dates using Where clause but it's not working. From and To date is same & one record comes within the same date but that getting eliminates.




todate 11/6/2018 12:00:00 AM //while debugging




if (toDate != "0")

var todate = DateTime.Parse(toDate).Date;
query = query.Where(x => x.CreatedDate.Date <= todate);

var homework = query.Select(x => new StudentHomework

HomeworkId = x.HomeworkID,
CreatedDate = x.CreatedDate
).OrderByDescending(i => i.CreatedDate).Skip(pageLong * recordLong - recordLong).Take(recordLong);
return homework.Any()
? Request.CreateResponse(HttpStatusCode.OK, homework)
: Request.CreateResponse(HttpStatusCode.NoContent);


From db coming one record to controller while debugging in VS



enter image description here



But query is showing 0 records & in ResulView getting below messages




Message = "The specified type member 'Date' is not supported in LINQ
to Entities. Only initializers, entity members, and entity navigation
properties are supported.




If I remove filter in my mobile app json result coming like this



"HomeworkId": 1400,
"ClassName": "Class 1",
"SectionName": "N/A",
"SubjectName": "Mathematics",
"IsAnswered": false,
"CreatedDate": "2018-11-06T00:00:00",









share|improve this question



















  • 1





    What are the milliseconds? Possibly that they are different on two dates.

    – Immorality
    Nov 15 '18 at 7:52






  • 1





    What database is this, what does the query translate to in sql, obviously this would be the first thing you checked right?

    – Michael Randall
    Nov 15 '18 at 7:57






  • 1





    What type of reference is query object? Add ToList() at end. might work

    – Md. Tazbir Ur Rahman Bhuiyan
    Nov 15 '18 at 8:05






  • 1





    Its actually unclear what you are asking, or what the results are you are getting

    – Michael Randall
    Nov 15 '18 at 8:06






  • 1





    You said that "Result has one record, while debugging controller in VS" but then result is coming up with 0 later on. Can you please show where are you using this result? if this is part of a controller may be useful to post rest of the action method up to the point where you return the actual action result

    – Sorin87bv
    Nov 15 '18 at 8:13

















0















I am filtering records based on Dates using Where clause but it's not working. From and To date is same & one record comes within the same date but that getting eliminates.




todate 11/6/2018 12:00:00 AM //while debugging




if (toDate != "0")

var todate = DateTime.Parse(toDate).Date;
query = query.Where(x => x.CreatedDate.Date <= todate);

var homework = query.Select(x => new StudentHomework

HomeworkId = x.HomeworkID,
CreatedDate = x.CreatedDate
).OrderByDescending(i => i.CreatedDate).Skip(pageLong * recordLong - recordLong).Take(recordLong);
return homework.Any()
? Request.CreateResponse(HttpStatusCode.OK, homework)
: Request.CreateResponse(HttpStatusCode.NoContent);


From db coming one record to controller while debugging in VS



enter image description here



But query is showing 0 records & in ResulView getting below messages




Message = "The specified type member 'Date' is not supported in LINQ
to Entities. Only initializers, entity members, and entity navigation
properties are supported.




If I remove filter in my mobile app json result coming like this



"HomeworkId": 1400,
"ClassName": "Class 1",
"SectionName": "N/A",
"SubjectName": "Mathematics",
"IsAnswered": false,
"CreatedDate": "2018-11-06T00:00:00",









share|improve this question



















  • 1





    What are the milliseconds? Possibly that they are different on two dates.

    – Immorality
    Nov 15 '18 at 7:52






  • 1





    What database is this, what does the query translate to in sql, obviously this would be the first thing you checked right?

    – Michael Randall
    Nov 15 '18 at 7:57






  • 1





    What type of reference is query object? Add ToList() at end. might work

    – Md. Tazbir Ur Rahman Bhuiyan
    Nov 15 '18 at 8:05






  • 1





    Its actually unclear what you are asking, or what the results are you are getting

    – Michael Randall
    Nov 15 '18 at 8:06






  • 1





    You said that "Result has one record, while debugging controller in VS" but then result is coming up with 0 later on. Can you please show where are you using this result? if this is part of a controller may be useful to post rest of the action method up to the point where you return the actual action result

    – Sorin87bv
    Nov 15 '18 at 8:13













0












0








0








I am filtering records based on Dates using Where clause but it's not working. From and To date is same & one record comes within the same date but that getting eliminates.




todate 11/6/2018 12:00:00 AM //while debugging




if (toDate != "0")

var todate = DateTime.Parse(toDate).Date;
query = query.Where(x => x.CreatedDate.Date <= todate);

var homework = query.Select(x => new StudentHomework

HomeworkId = x.HomeworkID,
CreatedDate = x.CreatedDate
).OrderByDescending(i => i.CreatedDate).Skip(pageLong * recordLong - recordLong).Take(recordLong);
return homework.Any()
? Request.CreateResponse(HttpStatusCode.OK, homework)
: Request.CreateResponse(HttpStatusCode.NoContent);


From db coming one record to controller while debugging in VS



enter image description here



But query is showing 0 records & in ResulView getting below messages




Message = "The specified type member 'Date' is not supported in LINQ
to Entities. Only initializers, entity members, and entity navigation
properties are supported.




If I remove filter in my mobile app json result coming like this



"HomeworkId": 1400,
"ClassName": "Class 1",
"SectionName": "N/A",
"SubjectName": "Mathematics",
"IsAnswered": false,
"CreatedDate": "2018-11-06T00:00:00",









share|improve this question
















I am filtering records based on Dates using Where clause but it's not working. From and To date is same & one record comes within the same date but that getting eliminates.




todate 11/6/2018 12:00:00 AM //while debugging




if (toDate != "0")

var todate = DateTime.Parse(toDate).Date;
query = query.Where(x => x.CreatedDate.Date <= todate);

var homework = query.Select(x => new StudentHomework

HomeworkId = x.HomeworkID,
CreatedDate = x.CreatedDate
).OrderByDescending(i => i.CreatedDate).Skip(pageLong * recordLong - recordLong).Take(recordLong);
return homework.Any()
? Request.CreateResponse(HttpStatusCode.OK, homework)
: Request.CreateResponse(HttpStatusCode.NoContent);


From db coming one record to controller while debugging in VS



enter image description here



But query is showing 0 records & in ResulView getting below messages




Message = "The specified type member 'Date' is not supported in LINQ
to Entities. Only initializers, entity members, and entity navigation
properties are supported.




If I remove filter in my mobile app json result coming like this



"HomeworkId": 1400,
"ClassName": "Class 1",
"SectionName": "N/A",
"SubjectName": "Mathematics",
"IsAnswered": false,
"CreatedDate": "2018-11-06T00:00:00",






c# asp.net .net linq class-library






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 8:41







CGPA6.4

















asked Nov 15 '18 at 7:50









CGPA6.4CGPA6.4

2,93431132




2,93431132







  • 1





    What are the milliseconds? Possibly that they are different on two dates.

    – Immorality
    Nov 15 '18 at 7:52






  • 1





    What database is this, what does the query translate to in sql, obviously this would be the first thing you checked right?

    – Michael Randall
    Nov 15 '18 at 7:57






  • 1





    What type of reference is query object? Add ToList() at end. might work

    – Md. Tazbir Ur Rahman Bhuiyan
    Nov 15 '18 at 8:05






  • 1





    Its actually unclear what you are asking, or what the results are you are getting

    – Michael Randall
    Nov 15 '18 at 8:06






  • 1





    You said that "Result has one record, while debugging controller in VS" but then result is coming up with 0 later on. Can you please show where are you using this result? if this is part of a controller may be useful to post rest of the action method up to the point where you return the actual action result

    – Sorin87bv
    Nov 15 '18 at 8:13












  • 1





    What are the milliseconds? Possibly that they are different on two dates.

    – Immorality
    Nov 15 '18 at 7:52






  • 1





    What database is this, what does the query translate to in sql, obviously this would be the first thing you checked right?

    – Michael Randall
    Nov 15 '18 at 7:57






  • 1





    What type of reference is query object? Add ToList() at end. might work

    – Md. Tazbir Ur Rahman Bhuiyan
    Nov 15 '18 at 8:05






  • 1





    Its actually unclear what you are asking, or what the results are you are getting

    – Michael Randall
    Nov 15 '18 at 8:06






  • 1





    You said that "Result has one record, while debugging controller in VS" but then result is coming up with 0 later on. Can you please show where are you using this result? if this is part of a controller may be useful to post rest of the action method up to the point where you return the actual action result

    – Sorin87bv
    Nov 15 '18 at 8:13







1




1





What are the milliseconds? Possibly that they are different on two dates.

– Immorality
Nov 15 '18 at 7:52





What are the milliseconds? Possibly that they are different on two dates.

– Immorality
Nov 15 '18 at 7:52




1




1





What database is this, what does the query translate to in sql, obviously this would be the first thing you checked right?

– Michael Randall
Nov 15 '18 at 7:57





What database is this, what does the query translate to in sql, obviously this would be the first thing you checked right?

– Michael Randall
Nov 15 '18 at 7:57




1




1





What type of reference is query object? Add ToList() at end. might work

– Md. Tazbir Ur Rahman Bhuiyan
Nov 15 '18 at 8:05





What type of reference is query object? Add ToList() at end. might work

– Md. Tazbir Ur Rahman Bhuiyan
Nov 15 '18 at 8:05




1




1





Its actually unclear what you are asking, or what the results are you are getting

– Michael Randall
Nov 15 '18 at 8:06





Its actually unclear what you are asking, or what the results are you are getting

– Michael Randall
Nov 15 '18 at 8:06




1




1





You said that "Result has one record, while debugging controller in VS" but then result is coming up with 0 later on. Can you please show where are you using this result? if this is part of a controller may be useful to post rest of the action method up to the point where you return the actual action result

– Sorin87bv
Nov 15 '18 at 8:13





You said that "Result has one record, while debugging controller in VS" but then result is coming up with 0 later on. Can you please show where are you using this result? if this is part of a controller may be useful to post rest of the action method up to the point where you return the actual action result

– Sorin87bv
Nov 15 '18 at 8:13












1 Answer
1






active

oldest

votes


















0














First of all feeling stupid to wasting time of everyone by asking confusing question. Here the issue was this line's .Date



query = query.Where(x => x.CreatedDate.Date <= todate);


In LINQ to Entities I should not have .Date and it is not allowing throwing Exception. After removing this everything working fine. I have try catch block but control was not jumping to it.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314647%2fif-from-to-date-is-same-record-not-filtering-linq%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    First of all feeling stupid to wasting time of everyone by asking confusing question. Here the issue was this line's .Date



    query = query.Where(x => x.CreatedDate.Date <= todate);


    In LINQ to Entities I should not have .Date and it is not allowing throwing Exception. After removing this everything working fine. I have try catch block but control was not jumping to it.






    share|improve this answer



























      0














      First of all feeling stupid to wasting time of everyone by asking confusing question. Here the issue was this line's .Date



      query = query.Where(x => x.CreatedDate.Date <= todate);


      In LINQ to Entities I should not have .Date and it is not allowing throwing Exception. After removing this everything working fine. I have try catch block but control was not jumping to it.






      share|improve this answer

























        0












        0








        0







        First of all feeling stupid to wasting time of everyone by asking confusing question. Here the issue was this line's .Date



        query = query.Where(x => x.CreatedDate.Date <= todate);


        In LINQ to Entities I should not have .Date and it is not allowing throwing Exception. After removing this everything working fine. I have try catch block but control was not jumping to it.






        share|improve this answer













        First of all feeling stupid to wasting time of everyone by asking confusing question. Here the issue was this line's .Date



        query = query.Where(x => x.CreatedDate.Date <= todate);


        In LINQ to Entities I should not have .Date and it is not allowing throwing Exception. After removing this everything working fine. I have try catch block but control was not jumping to it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 10:22









        CGPA6.4CGPA6.4

        2,93431132




        2,93431132





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53314647%2fif-from-to-date-is-same-record-not-filtering-linq%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20