Entity Framework. View return duplicate records

前端 未结 5 1218
面向向阳花
面向向阳花 2020-12-04 15:26

I use Entity Framework that contains view. And I have query:

var data = this.context.vwRevenues
    .Where(x => x.revenue >= 0);
    .OrderByDescending         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-04 15:53

    As per @Giovane Answer's

    We had the same problem in our system with Entity Framework dealing with views. Try using ROW_NUMBER () OVER () SQL to create a column with unique values​​, but did not work.

    I did the same thing but to make it work i need to open the EDMX model and then select a this column as an Entity Key.

    enter image description here

    Then it will work

    There is a very good article on this

    Duplicate Records

    The articles most important line is:

    When including a view in your Entity Model, the model seems to simply use the first not-nullable columns as primary key (as all columns used in the primary key should be non-nullable).

提交回复
热议问题