Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Why this query produce wrong results ?

Why this query produce wrong results ?

Scheduled Pinned Locked Moved Visual Basic
databasecsharpsql-serversysadmin
25 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dave Kreskowiak

    Dude. I don't have your database. I don't know what your overall objective is. I don't know what you're reasons are for anything and you've put up so many code snippets, I have no idea what you're referring to or what you're referring to when you say "slow". Without that stuff, I'm at a severe disadvantage in diagnosing your problems. YOU have to understand how EF works and you're not going to get that information from a few forum posts. I already told you, pick up a book on EF and Code First and work through them. I've already told you why your queries are returning 0's for values, but you don't seems to get it and you don't seem to understand the limitations of your design or of EF.

    A guide to posting questions on CodeProject

    Click this: Asking questions is a skill. Seriously, do it.
    Dave Kreskowiak

    D Offline
    D Offline
    dilkonika
    wrote on last edited by
    #21

    Hello Friend ! ( not dude ! ) You don't have my database , but you have my EF model from my first post. And as you have a lot's of experience , you can imagine how the database is. Anyway , my last question was not for database , but for a simple In memory For.. each loop that run slow. And I think it's not good to tell a someone " You have asked about this , ok take these books and read" . Then why this forum is still open , replace your webpage with a big poster : You that have problems with Entity ------ Read this book You that have problems with C# ------------ Read this book. .......

    D 1 Reply Last reply
    0
    • D dilkonika

      Hello Friend ! ( not dude ! ) You don't have my database , but you have my EF model from my first post. And as you have a lot's of experience , you can imagine how the database is. Anyway , my last question was not for database , but for a simple In memory For.. each loop that run slow. And I think it's not good to tell a someone " You have asked about this , ok take these books and read" . Then why this forum is still open , replace your webpage with a big poster : You that have problems with Entity ------ Read this book You that have problems with C# ------------ Read this book. .......

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #22

      dilkonika wrote:

      You don't have my database , but you have my EF model from my first post.

      Model, yes. Data, no.

      dilkonika wrote:

      Anyway , my last question was not for database , but for a simple In memory For.. each loop that run slow.

      Oh, but it IS about your database. You just refuse to listen to why when I've told you time and time again. Your data is NOT in memory!! You have a proxy object that EF must go back to requery the data for and that's why it's so slow! That's why I keep telling you to use an Include to get the child elements into memory! That's why I keep telling you to pick up a book on EF so you understand all of these little details you don't understand about EF, such a "deferred execution" and "lazy loading"!

      dilkonika wrote:

      You that have problems with Entity ------ Read this book
      You that have problems with C# ------------ Read this book.

      There's simply too much information to cover in a few forum posts! Forums can NOT answer all questions because forum posts can NOT convey all of the little details of an answer in the limited space available to us. If we could... if we did that we'd all be writing entire book chapters for forum posts! :mad:

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      D 2 Replies Last reply
      0
      • D Dave Kreskowiak

        dilkonika wrote:

        You don't have my database , but you have my EF model from my first post.

        Model, yes. Data, no.

        dilkonika wrote:

        Anyway , my last question was not for database , but for a simple In memory For.. each loop that run slow.

        Oh, but it IS about your database. You just refuse to listen to why when I've told you time and time again. Your data is NOT in memory!! You have a proxy object that EF must go back to requery the data for and that's why it's so slow! That's why I keep telling you to use an Include to get the child elements into memory! That's why I keep telling you to pick up a book on EF so you understand all of these little details you don't understand about EF, such a "deferred execution" and "lazy loading"!

        dilkonika wrote:

        You that have problems with Entity ------ Read this book
        You that have problems with C# ------------ Read this book.

        There's simply too much information to cover in a few forum posts! Forums can NOT answer all questions because forum posts can NOT convey all of the little details of an answer in the limited space available to us. If we could... if we did that we'd all be writing entire book chapters for forum posts! :mad:

        A guide to posting questions on CodeProject

        Click this: Asking questions is a skill. Seriously, do it.
        Dave Kreskowiak

        D Offline
        D Offline
        dilkonika
        wrote on last edited by
        #23

        Dim dt1 as DateTime=CDate("08/08/2014")

        Dim list1 = (From t In context.MyObj Select New With { _
        .Parent = t, _
        .chl = (From t2 In t.chld.AsQueryable.Where(Function(t3) t3.Date1>=dt1) Select t2)
        .sum1 =(From t2 in t.chld.AsQueryable.Where(Function(t2) t2.date1<dt1).Select(Function(t3) t3.quantity).DefaultIfEmpty
        }).ToList

        and after :

        For Each l In list1
        l.Parent.vls=l.sum1
        Next

        After the Tolist , all List1's : .Parent , .chl , .sum1 are in memory ? (That's the book's say about the .ToList , or show me an article that say the opposite ). So now the following , For...each is run on memory ? Or I'm wrong ? Thank you !

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          dilkonika wrote:

          You don't have my database , but you have my EF model from my first post.

          Model, yes. Data, no.

          dilkonika wrote:

          Anyway , my last question was not for database , but for a simple In memory For.. each loop that run slow.

          Oh, but it IS about your database. You just refuse to listen to why when I've told you time and time again. Your data is NOT in memory!! You have a proxy object that EF must go back to requery the data for and that's why it's so slow! That's why I keep telling you to use an Include to get the child elements into memory! That's why I keep telling you to pick up a book on EF so you understand all of these little details you don't understand about EF, such a "deferred execution" and "lazy loading"!

          dilkonika wrote:

          You that have problems with Entity ------ Read this book
          You that have problems with C# ------------ Read this book.

          There's simply too much information to cover in a few forum posts! Forums can NOT answer all questions because forum posts can NOT convey all of the little details of an answer in the limited space available to us. If we could... if we did that we'd all be writing entire book chapters for forum posts! :mad:

          A guide to posting questions on CodeProject

          Click this: Asking questions is a skill. Seriously, do it.
          Dave Kreskowiak

          D Offline
          D Offline
          dilkonika
          wrote on last edited by
          #24

          Hello ! This is my last question : I don't know why , but this is working :

          Partial Public Class Myobj
          Public Property id As Integer
          Public property name as string
          Public Overridable Property chld As ICollection(Of chld) = New HashSet(Of chld)
          End Class

          Partial Public Class Myobj
          <NotMapped> Public Property vls As integer
          End Class

          Partial Public Class chld
          Public Property id As Integer
          Public Property date1 as DateTime
          Public Property quantity as Integer
          Public Property ParentID as integer
          Public Overridable Property MyObj1 As MyObj
          End Class

          Public Class PseudoMyObj
          Inherits MyObj
          End Class

          Now on my form, I have this code :

          Dim dt1 as DateTime=CDate("08/08/2014")

          Dim list1 = (From t In context.MyObj Select New With { _
          .Parent = New PseudoMyObj With { _
          .chld = (From t2 in t.chld.AsQueryable.Where(Function(t3) t3.Date1>=dt1) Select t2), _
          .vls=(t.chld.AsQueryable.Where(Function(t2) t2.date1<dt1).Select(Function(t3) t3.quantity).DefaultIfEmpty.Sum()) _
          }).ToList

          dim mylist as IEnumerable(of MyObj)=list1.Select(Function(t2) t2.Parent)

          Please , I want your opinion , do you see anything wrong with this code ? Thank you !

          D 1 Reply Last reply
          0
          • D dilkonika

            Hello ! This is my last question : I don't know why , but this is working :

            Partial Public Class Myobj
            Public Property id As Integer
            Public property name as string
            Public Overridable Property chld As ICollection(Of chld) = New HashSet(Of chld)
            End Class

            Partial Public Class Myobj
            <NotMapped> Public Property vls As integer
            End Class

            Partial Public Class chld
            Public Property id As Integer
            Public Property date1 as DateTime
            Public Property quantity as Integer
            Public Property ParentID as integer
            Public Overridable Property MyObj1 As MyObj
            End Class

            Public Class PseudoMyObj
            Inherits MyObj
            End Class

            Now on my form, I have this code :

            Dim dt1 as DateTime=CDate("08/08/2014")

            Dim list1 = (From t In context.MyObj Select New With { _
            .Parent = New PseudoMyObj With { _
            .chld = (From t2 in t.chld.AsQueryable.Where(Function(t3) t3.Date1>=dt1) Select t2), _
            .vls=(t.chld.AsQueryable.Where(Function(t2) t2.date1<dt1).Select(Function(t3) t3.quantity).DefaultIfEmpty.Sum()) _
            }).ToList

            dim mylist as IEnumerable(of MyObj)=list1.Select(Function(t2) t2.Parent)

            Please , I want your opinion , do you see anything wrong with this code ? Thank you !

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #25

            I already told you why it works. Your first query, and the sub-queries, on the database engine. Getting the SQL query statement from the debugger and examining it in Notepad or in SQL Server Manager would have told you that. Your second query, the last statement in your post, is executed client-side, not on the database engine. I'm not telling you these things, like the above technique, because I like hearing myself type this crap. I tell you these things because this is how I debug and examine the functionality of EF. Have a nice life.

            A guide to posting questions on CodeProject

            Click this: Asking questions is a skill. Seriously, do it.
            Dave Kreskowiak

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups