2
我使用的EntityFramework 4.3.1,並試圖當我運行查詢像這樣運行實體框架查詢結果
Context.Set<KullaniciYetkiView>().Where(y => y.KullaniciId == kullaniciId && y.YetkiKod == yetkiKod)
查詢並返回115個記錄的預期。但是當我看着記錄時,他們都是一樣的。因此,我從Profiler聽取查詢,看看我缺少什麼,查看下面的查詢,並從管理工作室返回115條不同的記錄。
exec sp_executesql N'SELECT
[Extent1].[YetkiKod] AS [YetkiKod],
[Extent1].[KullaniciId] AS [KullaniciId],
[Extent1].[LokasyonId] AS [LokasyonId],
[Extent1].[YetkiId] AS [YetkiId],
[Extent1].[HiyerarsikKod] AS [HiyerarsikKod],
[Extent1].[LokasyonSeviye] AS [LokasyonSeviye],
[Extent1].[Yetkili] AS [Yetkili],
[Extent1].[Engelli] AS [Engelli],
[Extent1].[LokasyonEngelli] AS [LokasyonEngelli]
FROM [dbo].[sayKullaniciYetkiView] AS [Extent1]
WHERE ([Extent1].[KullaniciId] = @p__linq__0) AND ([Extent1].[YetkiKod] = @p__linq__1)',N'@p__linq__0 uniqueidentifier,@p__linq__1 nvarchar(4000)',@p__linq__0='283CCB41-3BDF-4BEF-BD26-E46191CA069D',@p__linq__1=N'FIN.SATISFATURA.E'
我認爲這個問題是在EF爲了證明這一點我像這樣運行
var yetkiler1 = Context.Set<KullaniciYetkiView>().Where(y => y.KullaniciId == kullaniciId && y.YetkiKod == yetkiKod).Distinct().ToList();
var yetkiler2 = Context.Set<KullaniciYetkiView>().Where(y => y.KullaniciId == kullaniciId && y.YetkiKod == yetkiKod).ToList().Distinct();
首先查詢返回115行,第二個返回1.
代碼我錯過了什麼?
在此先感謝。
這個KullaniciId列似乎有點可疑。生成的查詢將其視爲唯一ID,但它會返回115條記錄? –
這可能是您的模型配置有問題。檢查出http://stackoverflow.com/a/7955773/1099260。 –
是的,它必須返回115條記錄。 –