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. Type of a query ?

Type of a query ?

Scheduled Pinned Locked Moved LINQ
databasequestion
3 Posts 3 Posters 4 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.
  • M Offline
    M Offline
    Mohammad Dayyan
    wrote on last edited by
    #1

    Hi, What is the real type of query in the following code?

    RezaRestaurant.SQL.DataClasses1DataContext dbc = new RezaRestaurant.SQL.DataClasses1DataContext();
    var query = from q in dbc.Bills
    where (q.dateTime >= startTime && q.dateTime < endTime)
    orderby q.dateTime ascending
    select new
    {
    q.Number,
    q.Type,
    q.Table,
    q.Price,
    q.Date
    };

    I'm gonna omit var and put the type of query instead. Thanks.

    D I 2 Replies Last reply
    0
    • M Mohammad Dayyan

      Hi, What is the real type of query in the following code?

      RezaRestaurant.SQL.DataClasses1DataContext dbc = new RezaRestaurant.SQL.DataClasses1DataContext();
      var query = from q in dbc.Bills
      where (q.dateTime >= startTime && q.dateTime < endTime)
      orderby q.dateTime ascending
      select new
      {
      q.Number,
      q.Type,
      q.Table,
      q.Price,
      q.Date
      };

      I'm gonna omit var and put the type of query instead. Thanks.

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

      It will be of same type as q. You can use ToList method and get all the data in a generic list. So, your query should look like:

      List< Bills > query = (from q in dbc.Bills
      where (q.dateTime >= startTime && q.dateTime < endTime)
      orderby q.dateTime ascending
      select q).ToList< Bills >();

      Here, I assume that dbc.Bills is of type Bills. If it is something else, use that type. Also, remove spaces after < and before >. Edit: changed the code.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      modified on Sunday, January 17, 2010 5:35 AM

      1 Reply Last reply
      0
      • M Mohammad Dayyan

        Hi, What is the real type of query in the following code?

        RezaRestaurant.SQL.DataClasses1DataContext dbc = new RezaRestaurant.SQL.DataClasses1DataContext();
        var query = from q in dbc.Bills
        where (q.dateTime >= startTime && q.dateTime < endTime)
        orderby q.dateTime ascending
        select new
        {
        q.Number,
        q.Type,
        q.Table,
        q.Price,
        q.Date
        };

        I'm gonna omit var and put the type of query instead. Thanks.

        I Offline
        I Offline
        i j russell
        wrote on last edited by
        #3

        It is an Anonymous Type containing properties of Number, Type, Table, Price and Date as requested in the final "select new { }" Linq expression. The var keyword was added specifically for this scenario.

        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