locked
if I use ToString() conversion Where(e => e.myfield.ToString()=="myvar") does it slowdown query performance RRS feed

  • Question

  • User283528319 posted

    hi all

    there are 2 ways to get result from query as int or as string like below

    as string

    int ToplamRecordSayisi = _VNTSClientContext.Set<Gonderiler>().Where(e => e.EnstituId == EnstituId && e.GonderiDurumuId.ToString()=="mystring").Count();

    as int

    int ToplamRecordSayisi = _VNTSClientContext.Set<Gonderiler>().Where(e => e.EnstituId == EnstituId && e.GonderiDurumuId==myint).Count();

    if I use .ToString() does this conversion slows the query?

    Thursday, August 1, 2019 2:02 PM

Answers

  • User475983607 posted

    hi all

    there are 2 ways to get result from query as int or as string like below

    as string

    int ToplamRecordSayisi = _VNTSClientContext.Set<Gonderiler>().Where(e => e.EnstituId == EnstituId && e.GonderiDurumuId.ToString()=="mystring").Count();

    as int

    int ToplamRecordSayisi = _VNTSClientContext.Set<Gonderiler>().Where(e => e.EnstituId == EnstituId && e.GonderiDurumuId==myint).Count();

    if I use .ToString() does this conversion slows the query?

    The int is quicker because the SQL does not have to invoke the convert function.

    SELECT [e].[BlogId], [e].[Url]
    FROM [Blogs] AS [e]
    WHERE [e].[BlogId] = 1
    SELECT [e].[BlogId], [e].[Url]
    FROM [Blogs] AS [e]
    WHERE CONVERT(VARCHAR(11), [e].[BlogId]) = N'1'

    You can see and test this yourself using SQL Server Profiler.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 1, 2019 2:49 PM

All replies

  • User475983607 posted

    hi all

    there are 2 ways to get result from query as int or as string like below

    as string

    int ToplamRecordSayisi = _VNTSClientContext.Set<Gonderiler>().Where(e => e.EnstituId == EnstituId && e.GonderiDurumuId.ToString()=="mystring").Count();

    as int

    int ToplamRecordSayisi = _VNTSClientContext.Set<Gonderiler>().Where(e => e.EnstituId == EnstituId && e.GonderiDurumuId==myint).Count();

    if I use .ToString() does this conversion slows the query?

    The int is quicker because the SQL does not have to invoke the convert function.

    SELECT [e].[BlogId], [e].[Url]
    FROM [Blogs] AS [e]
    WHERE [e].[BlogId] = 1
    SELECT [e].[BlogId], [e].[Url]
    FROM [Blogs] AS [e]
    WHERE CONVERT(VARCHAR(11), [e].[BlogId]) = N'1'

    You can see and test this yourself using SQL Server Profiler.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 1, 2019 2:49 PM
  • User283528319 posted

    thanks

    Thursday, August 1, 2019 3:24 PM