LINQ to SQL query has invalid values ​​in results

I have a LINQ query that has incorrect results, but when I process the SQL data, the SQL results are correct.

ApplicationsEntities context = new ApplicationsEntities(); var query = from documentation in context.Documnetations where documentation.Application_Version_ID == app_ver_id orderby documentation.Name select documentation; docs = query.ToList<Documnetation>(); 

I am returning two duplicates: "How to install Office 2003" and "How to install Office 2003" enter image description here

The following is the result of profiled SQL: enter image description here

What could happen to assigning results from generated SQL?

+4
source share
1 answer

Comment Based Update

Your linq request is fine, but in your model you have to set the primary key / object key

Linq to Sql

In your dbml you need to change your primary key from Application_Version_ID to Documentation_Id

Linq to Entities

In your model you need to change the entity key from Application_Version_ID to Documentation_Id

+6
source

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


All Articles