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. How do I identify that a record is a result or a Default?

How do I identify that a record is a result or a Default?

Scheduled Pinned Locked Moved LINQ
question
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.
  • L Offline
    L Offline
    LongRange Shooter
    wrote on last edited by
    #1

    when executing the following code:

    SomeObject myObject = context.Table.SelectSingleOrDefault();

    How can I easily determin that the value of myObject has been set to default instead of a value? Thanks

    M 1 Reply Last reply
    0
    • L LongRange Shooter

      when executing the following code:

      SomeObject myObject = context.Table.SelectSingleOrDefault();

      How can I easily determin that the value of myObject has been set to default instead of a value? Thanks

      M Offline
      M Offline
      Mirko1980
      wrote on last edited by
      #2

      Check if myObject == default(SomeObject). Obviously, if the there is a single result whose value is the default falue (e.g. 0 if SomeObject is an int), you can't tell apart form the case when there is no value and the default is returned. You can always check context.Table.Count() != 0 to see if there are values, or use context.Table.Single() and handle the exception if there are no values.

      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