LINQ to SQL query has wrong values in results

隐身守侯 提交于 2019-12-10 17:26:32

问题


I have a LINQ query that has the incorrect results, but when I profile the SQL generated, 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 get back two duplicates : "How to install Office 2003" and "How to install office 2003"

Below is the output of the profiled SQL:

What could be happening to the assignment of the results from the generated SQL?


回答1:


Update based on comments

Your linq query is fine, but in your model you have to set the Primary Key/Entity 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 your entity key from Application_Version_ID to Documentation_Id



来源:https://stackoverflow.com/questions/9415799/linq-to-sql-query-has-wrong-values-in-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!