gpt4 book ai didi

c# Linq 和 SQL 之间的不同结果

转载 作者:行者123 更新时间:2023-11-30 16:50:53 25 4
gpt4 key购买 nike

我尝试使用 EF6 从 MSSQL 数据库中获取一些数据:

IQueryable<Kundentree1> tmp = from f in db.Kundentree1 select f ;

Kundentree1 是数据库上的SQL-View

因为我没有过滤所有结果:

tmp = tmp.Where(k => k.Strasse
.ToLower()
.Trim().Contains(search.Strasse
.ToLower()
.Trim()))
.Distinct();

(这不是唯一的,还有一些..)

在我的程序结束时:

var sql = tmp.ToString();
return View(tmp);

在我的测试例程中,tmp 返回 7 个项目作为结果,但项目 0 - 6 是相同的。

如果我使用 SqlStatement (SQL),我也会得到 7 个项目,但在这种情况下,正确的结果是 7 个不同的项目。

有什么问题可能出在哪里的提示吗?

更新:

完整生成的 SQL 代码(和正确的工作)

SELECT 
[Extent1].[Firmenname] AS [Firmenname],
[Extent1].[rechtsform] AS [rechtsform],
[Extent1].[Strasse] AS [Strasse],
[Extent1].[Land] AS [Land],
[Extent1].[Postleitzahl] AS [Postleitzahl],
[Extent1].[Ort] AS [Ort],
[Extent1].[Name] AS [Name],
[Extent1].[Personen_ID] AS [Personen_ID],
[Extent1].[Firmen_ID] AS [Firmen_ID],
[Extent1].[Adressen_ID] AS [Adressen_ID],
[Extent1].[sex] AS [sex],
[Extent1].[Vorwahl] AS [Vorwahl],
[Extent1].[Tel1] AS [Tel1],
[Extent1].[zahlungskondition] AS [zahlungskondition],
[Extent1].[sperrkennzeichen] AS [sperrkennzeichen],
[Extent1].[sendkatalag] AS [sendkatalag],
[Extent1].[lastkatalog] AS [lastkatalog],
[Extent1].[ID] AS [ID],
[Extent1].[NACHNAME] AS [NACHNAME],
[Extent1].[VORNAME] AS [VORNAME],
[Extent1].[ZKTEXT] AS [ZKTEXT],
[Extent1].[FAX] AS [FAX],
[Extent1].[KNR] AS [KNR],
[Extent1].[UID] AS [UID],
[Extent1].[firmenbuch] AS [firmenbuch],
[Extent1].[email] AS [email],
[Extent1].[Lieferant] AS [Lieferant],
[Extent1].[PERS_VORNAME] AS [PERS_VORNAME],
[Extent1].[PERS_NACHNAME] AS [PERS_NACHNAME],
[Extent1].[PERS_sex] AS [PERS_sex],
[Extent1].[Titel] AS [Titel],
[Extent1].[Zusatz] AS [Zusatz],
[Extent1].[Position] AS [Position],
[Extent1].[PERS_EMAIL] AS [PERS_EMAIL],
[Extent1].[PERSONEN_GRUPPE_ID] AS [PERSONEN_GRUPPE_ID],
[Extent1].[NEWSLETTER] AS [NEWSLETTER],
[Extent1].[HEROLD_ID] AS [HEROLD_ID],
[Extent1].[INFOTEXT] AS [INFOTEXT],
[Extent1].[DISG] AS [DISG],
[Extent1].[HANDEL] AS [HANDEL],
[Extent1].[AdressenTYP] AS [AdressenTYP],
[Extent1].[BUNDESLAND] AS [BUNDESLAND],
[Extent1].[CANBOX] AS [CANBOX],
[Extent1].[KatalogTyp] AS [KatalogTyp],
[Extent1].[KatalogBezeichnung] AS [KatalogBezeichnung]
FROM (SELECT
[Kundentree1].[Firmenname] AS [Firmenname],
[Kundentree1].[rechtsform] AS [rechtsform],
[Kundentree1].[Strasse] AS [Strasse],
[Kundentree1].[Land] AS [Land],
[Kundentree1].[Postleitzahl] AS [Postleitzahl],
[Kundentree1].[Ort] AS [Ort],
[Kundentree1].[Name] AS [Name],
[Kundentree1].[Personen_ID] AS [Personen_ID],
[Kundentree1].[Firmen_ID] AS [Firmen_ID],
[Kundentree1].[Adressen_ID] AS [Adressen_ID],
[Kundentree1].[sex] AS [sex],
[Kundentree1].[Vorwahl] AS [Vorwahl],
[Kundentree1].[Tel1] AS [Tel1],
[Kundentree1].[zahlungskondition] AS [zahlungskondition],
[Kundentree1].[sperrkennzeichen] AS [sperrkennzeichen],
[Kundentree1].[sendkatalag] AS [sendkatalag],
[Kundentree1].[lastkatalog] AS [lastkatalog],
[Kundentree1].[ID] AS [ID],
[Kundentree1].[NACHNAME] AS [NACHNAME],
[Kundentree1].[VORNAME] AS [VORNAME],
[Kundentree1].[ZKTEXT] AS [ZKTEXT],
[Kundentree1].[FAX] AS [FAX],
[Kundentree1].[KNR] AS [KNR],
[Kundentree1].[UID] AS [UID],
[Kundentree1].[firmenbuch] AS [firmenbuch],
[Kundentree1].[email] AS [email],
[Kundentree1].[Lieferant] AS [Lieferant],
[Kundentree1].[PERS_VORNAME] AS [PERS_VORNAME],
[Kundentree1].[PERS_NACHNAME] AS [PERS_NACHNAME],
[Kundentree1].[PERS_sex] AS [PERS_sex],
[Kundentree1].[Titel] AS [Titel],
[Kundentree1].[Zusatz] AS [Zusatz],
[Kundentree1].[Position] AS [Position],
[Kundentree1].[PERS_EMAIL] AS [PERS_EMAIL],
[Kundentree1].[PERSONEN_GRUPPE_ID] AS [PERSONEN_GRUPPE_ID],
[Kundentree1].[NEWSLETTER] AS [NEWSLETTER],
[Kundentree1].[HEROLD_ID] AS [HEROLD_ID],
[Kundentree1].[INFOTEXT] AS [INFOTEXT],
[Kundentree1].[DISG] AS [DISG],
[Kundentree1].[HANDEL] AS [HANDEL],
[Kundentree1].[AdressenTYP] AS [AdressenTYP],
[Kundentree1].[BUNDESLAND] AS [BUNDESLAND],
[Kundentree1].[CANBOX] AS [CANBOX],
[Kundentree1].[KatalogTyp] AS [KatalogTyp],
[Kundentree1].[KatalogBezeichnung] AS [KatalogBezeichnung]
FROM [dbo].[Kundentree1] AS [Kundentree1]) AS [Extent1]
WHERE (( CAST(CHARINDEX(LTRIM(RTRIM(LOWER('Salv'))), LTRIM(RTRIM(LOWER([Extent1].[Firmenname])))) AS int)) > 0) AND ( NOT (([Extent1].[Postleitzahl] IS NULL) OR ((LEN([Extent1].[Postleitzahl])) = 0))) AND (( CAST(CHARINDEX(LTRIM(RTRIM('4482')), LTRIM(RTRIM([Extent1].[Postleitzahl]))) AS int)) > 0)

最佳答案

感谢 Ivan Stoev:

在数据库 View 上创建键

在我的例子中,它是一个我需要工作的假 key (uniqueidentifier newID())

关于c# Linq 和 SQL 之间的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34337234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com