Unbelievable duplicate in an Entity Framework Query

前端 未结 5 725
情书的邮戳
情书的邮戳 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:23

    I had a similar issue and I solved it by changing the merge option of the ObjectSet. Example:

        using (TargetDBDataContext db = new TargetDBDataContext())
        {
            db.SomeView.MergeOption = System.Data.Objects.MergeOption.NoTracking;
            return db. SomeView.ToList();
        }
    

    It looks like entity framework(EF) doesn’t handle correctly views that have duplicated primary keys or no primary keys at all. So when there are two rows that EF is considering equal, EF will load first row as it should but will not load the second row because it will consider it’s already loaded.

提交回复
热议问题