C#实体LINQ返回错误并重复值 [英] C# Entity LINQ returns wrong and duplicate values

查看:49
本文介绍了C#实体LINQ返回错误并重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码:

List<vw_GetIMeasurements> Imeasurements = context.vw_GetIMeasurements.Where(f => f.MEMBERID == userID).Distinct().ToList();

这将返回一个包含其应有的12个值的列表,但这些值始终相同(即使它们不在数据库中也是如此(即使它们是不同的也应解决)

This returns a list with 12 Values like it should but these values are always the same(even though they aren't in the DB.(Even if they were distinct should solve this)

数据库:

返回的原始值也是错误的. 造成此问题的原因是什么,我该如何解决?

The raw value that is returned is also wrong. What would be the cause of this issue and how can I resolve it?

推荐答案

我以前遇到过此问题-事实证明该视图未设置唯一的entity keys-确保您的视图的主键是自动的实体框架创建的确是独一无二的...

I have had this problem before - it turned out that the view did not have unique entity keys set - make sure your primary keys for your view that is auto created by entity framework is indeed unique...

这篇关于C#实体LINQ返回错误并重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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