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 build query in Linq

How build query in Linq

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

    Hi, I'm starting with Linq. My point is simple, I think. I'm filtering rows in LinqDataSource in event OnSelecting. I want to build a query like this: "select * from t_Rates WHERE (t_Rates.id_Contract = " + ddContract.SelectedValue + ") AND (t_Rates.id_Service = " + ddService.SelectedValue + ") AND (" + strOr +")"; strOr is a string build according if some other control's values are set or not and look like this: "t_Rates.id_UnitRange = 22 OR t_Rates.id_UnitRange = 33 OR t_Rates.id_Season = 34..." and some other OR could be here... Now, I would like to know how o transform this into a very dynamic Linq query construction in order to assing to e.Result inside OnSelecting event. Thanks a lot !!!

    M 1 Reply Last reply
    0
    • A alfhv

      Hi, I'm starting with Linq. My point is simple, I think. I'm filtering rows in LinqDataSource in event OnSelecting. I want to build a query like this: "select * from t_Rates WHERE (t_Rates.id_Contract = " + ddContract.SelectedValue + ") AND (t_Rates.id_Service = " + ddService.SelectedValue + ") AND (" + strOr +")"; strOr is a string build according if some other control's values are set or not and look like this: "t_Rates.id_UnitRange = 22 OR t_Rates.id_UnitRange = 33 OR t_Rates.id_Season = 34..." and some other OR could be here... Now, I would like to know how o transform this into a very dynamic Linq query construction in order to assing to e.Result inside OnSelecting event. Thanks a lot !!!

      M Offline
      M Offline
      Mohammad Dayyan
      wrote on last edited by
      #2

      You should write a something like this :

      alfhv wrote:

      "select * from t_Rates WHERE (t_Rates.id_Contract = " + ddContract.SelectedValue + ") AND (t_Rates.id_Service = " + ddService.SelectedValue + ") AND (" + strOr +")";

      var query = from q in t_Rates
      where t_Rates.id_Contract == ddContract.SelectedValue
      && t_Rates.id_Service == ddService.SelectedValue
      selecr q

      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