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