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. Linq Compare

Linq Compare

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinq
3 Posts 3 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.
  • S Offline
    S Offline
    spankyleo123
    wrote on last edited by
    #1

    Hi people, I would like to know of a way to compare existing users in the database while adding new ones. If user already exists then alert the user...if not add new user. I hope this makes sense, Thanks,

    N D 2 Replies Last reply
    0
    • S spankyleo123

      Hi people, I would like to know of a way to compare existing users in the database while adding new ones. If user already exists then alert the user...if not add new user. I hope this makes sense, Thanks,

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      This isn't a Linq question. Query the database before adding the user or have the insert stored proc check. What is difficult about that?


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • S spankyleo123

        Hi people, I would like to know of a way to compare existing users in the database while adding new ones. If user already exists then alert the user...if not add new user. I hope this makes sense, Thanks,

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        This should work:

        var objUser = (from user in userList
        where user.UserName = newUser.UserName
        select user
        )

        Although, you should consider the number of users in your database as well. There is no point in getting 10000 or likewise records just for validation. IMO a trip to database server would cost less than this.

        "No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem

        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