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. Entity framework : How to get DBcontext.ChangeTracker.Entries(of ???)) for a class known only at runtime

Entity framework : How to get DBcontext.ChangeTracker.Entries(of ???)) for a class known only at runtime

Scheduled Pinned Locked Moved Visual Basic
tutorialquestionloungelearning
2 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 Offline
    D Offline
    dilkonika
    wrote on last edited by
    #1

    I'm using entity framework I'm trying to make a general function that works for an object for which the class is known only at runtime. I have an instruction that use an expression similar to this :

    context.ChangeTracker.Entries(of Myobj1)

    Of course that if I know the class name "MyObj1" the above expression is working correctly. But at runtime , I only have an variable :

    Dim tp as type

    which contain the class , and i need an expression like this :

    context.ChangeTracker.Entries(of tp)

    Thank you !

    D 1 Reply Last reply
    0
    • D dilkonika

      I'm using entity framework I'm trying to make a general function that works for an object for which the class is known only at runtime. I have an instruction that use an expression similar to this :

      context.ChangeTracker.Entries(of Myobj1)

      Of course that if I know the class name "MyObj1" the above expression is working correctly. But at runtime , I only have an variable :

      Dim tp as type

      which contain the class , and i need an expression like this :

      context.ChangeTracker.Entries(of tp)

      Thank you !

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

      My bad. I misunderstood what you were doing. In order for a Generic to work, the types used must be known at compile-time, not run-time. I've never done what you're trying to do, nor seen it done specifically with EF before, but you may want to look into these[^] possibilities. You'd have to create a method that generates the entire ChangeTracker.Entities() call at runtime.

      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