EntityFramework returns corrupted / changed data from SQL Server view

I have a simple query from a view in SQL Server:

SELECT [PricePerM]
FROM RealtyStatParent
ORDER BY PricePerM

When I execute a query in SQL Management Studio, I get the correct results. This means that I get 2532 lines, starting from 1.00 and ending with 173543.6893.

When I make a request from C # using the framework entity, I got the same results:

var justDecimals = context.RealtyStatParents                
    .OrderBy(item => item.PricePerM)
    .Select(item => item.PricePerM)
    .ToArray();

Nothing special so far. But what I really don't understand is the following query. First I select the whole lines, and then I select the price (decimal).

var entireRows = context.RealtyStatParents                
    .OrderBy(item => item.PricePerM)        
    .ToArray();

var decimalFromRows = entireRows 
    .Select(item => item.PricePerM)
    .ToArray();

Many PricePerM values ​​are repeated (value 1 or 48) instead of the actual value, and the result set is not properly ordered.

Defining a string in an EF designer is simple:

public partial class RealtyStatParent
{
    public Nullable<decimal> PricePerM { get; set; }
    public int BusinessCategory { get; set; }
    public decimal obec_kod { get; set; }
    public Nullable<int> ParentCategoryId { get; set; }
}

enter image description here

UPDATE

, - Entity Framework, , . EF , Entity Key Column BusinessCategory obec_kod, . , , .

+4
1

. , EF , EF , , , .

SELECT . . EF . EF , , EF 2 .

, EDMX, " ". , EntityKey, true. .

- "" EF EF. LinqToSQL - . , LinqToSql , EF , , . , Microsoft " , " . , , .

enter image description here

+1

Source: https://habr.com/ru/post/1618960/


All Articles