1

我有一个情况,我不明白。案例非常简单。我使用通用存储库来处理我的数据库。http://efgenericrepository.codeplex.com/一切都很好,但现在只有 1 个视图我遇到了问题。我认为当我执行查询时,EF 会返回一个单词数据。

这是我在 SQL Manager 中的 SQL 结果:

Select * 
from Vw_HoursMOPJustificated 
where IdUser = 20 
and ActionDate = '2012-08-22' and Hour < 24

IdMopTime | IdJustification | IdJustificationType

44      30                 8
44      40                11
44      43                13
45      31                 8
45      41                12
46      32                 8

当我执行这个简单的代码时,这是我在 C# 中的结果。

MyIGFEntities entity = new MyIGFEntities();

var table = new Repository<MyIGF.Models.Vw_HoursMOPJustificated>(new MyIGFEntities())
    .Find(x => x.ActionDate == ActionDate && x.IdUser == IdUser && x.Hour < 24);

IdMopTime | IdJustification | IdJustificationType
44 | 30 | 8
44 | 30 | 8
44 | 30 | 8
45 | 31 | 8
45 | 31 | 8
46 | 32 | 8

任何人都可以帮助我吗?

4

1 回答 1

1

You must correct your edmx (quite sure you have one).

On your Vw_HoursMOPJustificated entity and set Primary Key to true for IdMopTime, IdJustification and IdJustificationType (at least).

To check if everything is correct, try to get data from your edmx, and see if you have correct distinct data.

Sometimes (and mainly with views, which don't have a "real" primary key in db), the primary keys (or the properties which makes each row distinct) are badly retrieved, and you get this kind of confusing results.

于 2012-09-04T09:44:08.810 回答