实体框架我们的行为。 [英] Entity Framework Weired behavior.

查看:67
本文介绍了实体框架我们的行为。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EF 4从视图中选择行。这是从视图中进行的简单选择操作。由VS  2010生成的edmx中的存储架构表示它有多个主键,这很好。我提供的条件是检查
ProductId是否相同。代码 类似于以下内容:

I am selecting the rows from view using EF 4. It is a simple select operation from the view. The Storage Schema in edmx, generated by VS 2010 says it has multiple primary keys, which is fine. The condition that I am supplying is to check if the ProductId is same or not. The code is similar to the following:

var returnedResult = ctx.vw_MyProductList.Where(x => x.ProductName.Equals(suppliedProductId,StringComparision.OrdinalIgnoreCase))。ToList( );

var returnedResult=ctx.vw_MyProductList.Where(x=>x.ProductName.Equals(suppliedProductId, StringComparision.OrdinalIgnoreCase)).ToList();

视图中有两条与条件匹配的记录。它返回两条我所期待的记录。但问题是两次返回相同的第一条记录。看起来框架知道有两条记录,但是在行中某处,
将第一条记录复制到下一条记录并返回。

There are two records in the view that matches the condition. It returns two records that is what I was expecting. But the thing is it is returning the same first record twice. Looks like Framework knew there are two records, but somewhere in the line it copies the first record to the next and returns.

我检查了SQL分析器,复制了它并在SQL-Server Mgmt Studio中执行,它正在按预期正确返回行。

I checked in the SQL profiler, copied it and executed in the SQL-Server Mgmt Studio and it is returning the rows correctly as expected.

除非我做错了,否则对我没有任何意义。我删除了.edmx并重新开始但没有工作。它只是一个简单的反对视图的选择语句。

It doesn't make any sense to me, unless I am doing something wrong. I deleted the .edmx and started over but didn't work. It is just a simple select statement against view.

看起来EF对视图的语句有点不同,是吗?

Looks like EF treats statements against Views a bit differently, does it?

Suraj。

Suraj Upreti

Suraj Upreti

推荐答案

Hi Suraj,

欢迎来到MSDN论坛。

我试图重现您的问题,但失败了。我的环境是带有Entity Framework 5的Visual Studio 2010,以及带有复合主键的表(数据库第一种方法)。你可以试试
这个实体框架5的问题吗?

祝你有个愉快的一天。


这篇关于实体框架我们的行为。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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