LINQ to SQL查询在结果中有错误的值 [英] LINQ to SQL query has wrong values in results

查看:161
本文介绍了LINQ to SQL查询在结果中有错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ApplicationsEntities context = new ApplicationsEntities(); 
var query = from context.Documnetations
其中documentation.Application_Version_ID == app_ver_id
orderby documentation.Name
选择文档;
docs = query.ToList< Documnetation>();

我收到两个重复的内容:如何安装Office 2003和如何安装Office 2003



下面是剖析SQL的输出:



从生成的SQL分配结果可能会发生什么?

解决方案

更新基于评论



您的LINQ查询是正确的,但在您的模型中,您必须设置主键/实体键



Linq-to-Sql



在您的 dbml ,您需要将主键从 Application_Version_ID 更改为 Documentation_Id



Linq-to-Entities



在您的模型中,您需要从<$中更改您的实体密钥c $ c> Application_Version_ID to Documentation_Id


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?

解决方案

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

这篇关于LINQ to SQL查询在结果中有错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆