Unbelievable duplicate in an Entity Framework Query

前端 未结 5 602
情书的邮戳
情书的邮戳 2021-02-07 11:40

My SQL query against a particular view returns me 3 different rows.

 select * from vwSummary
 where vidate >= \'10-15-2010\' and vidate <= \'10-15-2010\'
          


        
5条回答
  •  执念已碎
    2021-02-07 12:18

    WORKAROUND: I changed my query like this and it works. But still I want to go back to the one shown above as I have to iterate again for more processing.

    List p1 = (from v in db.vwSummary
                         where v.viDate >= firstVisibleDate && v.viDate <= lastVisibleDate
                         && v.IDNo == "0330"
                              select new 
    {
    a = v.a
    b = v.b
    }
    ).ToList();
    

    I found the source of the problem from here and here. I guessed this should be an issue as I didnt have a very good key in my view as the view was more of a summary report. So I am sticking to the workaround I found in my other answer.

    So if you find a similar issue, the problem is, add a proper primary key to your table or the view. If you cannot add one try something similar to the work around.

提交回复
热议问题