Entity Framework is a framework for creating entities. Return duplicate records to view

duplicates entity-framework

Question

Entity Framework, which has a view, is what I use. And my question is:

var data = this.context.vwRevenues
    .Where(x => x.revenue >= 0);
    .OrderByDescending(x => x.year)
    .ThenByDescending(x => x.month)
    .Take(10)
    .ToList();

This query produces a list of entities, yet the first entity is equivalent to the fifth.

data[0] == data[4] // true

I execute the SQL script I copied from SQL Tracer into SQL Management Studio, and it produces a different set of results.

1
43
7/18/2016 5:24:40 PM

Accepted Answer

According to @Giovane Answers

In our system, the Entity Framework's handling of views caused the similar issue. To construct a column with unique values, try using ROW NUMBER () OVER () SQL, but it didn't work.

I performed the same action, but in order for it to succeed, I had to access the EDMX model and choose this column as a Element Key..

enter image description here

Then it will function.

There is an excellent article on this.

Double Records

The key passage in the article is:

Your Entity Model seems to utilize the first not-nullable columns as the main key whenever you include a view in it (as all columns used in the primary key should be non-nullable).

83
9/28/2012 5:31:54 AM

Popular Answer

All you have to do iscontext.viewname.AsNoTracking().Where(x => x.ColumnName != null);



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow