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. LINQ
  4. Scat object ref

Scat object ref

Scheduled Pinned Locked Moved LINQ
databasequestion
2 Posts 2 Posters 3 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.
  • R Offline
    R Offline
    reza toorani
    wrote on last edited by
    #1

    hi everybody I have a method by following signature and body: private void LoadByItem(Item item) { MyDBDataContext my = new MyDBDataContext(); var query = from q in my.Items where q.Id == item.Id select q; item = query.First<Item>>; } when I send the argument to the above method, after method process I get nothing in item while in the method item had value. I think after assigning item to query it work as a value type not a reference type. please let me know how can I get the reference of item without using ref in function signature.

    J 1 Reply Last reply
    0
    • R reza toorani

      hi everybody I have a method by following signature and body: private void LoadByItem(Item item) { MyDBDataContext my = new MyDBDataContext(); var query = from q in my.Items where q.Id == item.Id select q; item = query.First<Item>>; } when I send the argument to the above method, after method process I get nothing in item while in the method item had value. I think after assigning item to query it work as a value type not a reference type. please let me know how can I get the reference of item without using ref in function signature.

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Sorry, that won't work unless you use ref. Do this instead:

      Item loadedItem = LoadByItem(item.Id);
      ...
      private Item LoadByItem(int id) // if Id is not an int, change this accordingly
      {
          var matches = from item in new MyDBDataContext().Items
                     where item.Id == id
                        select item;

      return matches.First();
      }

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: I'm Offended That You're Offended! The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      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