LINQ and ToList when querying multiple sources

  • Thread starter Thread starter Marc S
  • Start date Start date
M

Marc S

var qry = from s in dbCxt.Services
from j in s.Jobs
where s.ID == 200
select new { s, j };


I want to call qry.ToList() but with the list containing anonomyous
types I don't know how to create a List object to support that. I want
to get all records in a List so that I only have to make 1 call to the
database. Is this even possible?
 
Yes; use ToList()

i.e. either:

var list = qry.ToList();

or

var list = ( from s in dbCxt.Services
from j in s.Jobs
where s.ID == 200
select new { s, j }).ToList();

It will be a list of anon-types, but that is fine.

Marc
 
Marc said:
var qry = from s in dbCxt.Services
from j in s.Jobs
where s.ID == 200
select new { s, j };


I want to call qry.ToList() but with the list containing anonomyous
types I don't know how to create a List object to support that. I want
to get all records in a List so that I only have to make 1 call to the
database. Is this even possible?

Use 'var' again e.g.
var list = qry.ToList();
 
Yes; use ToList()

i.e. either:

var list = qry.ToList();

or

var list = ( from s in dbCxt.Services
           from j in s.Jobs
           where s.ID == 200
           select new { s, j }).ToList();

It will be a list of anon-types, but that is fine.

Marc

Exactly waht I need. I am in the process of discovering LINQ to
rewrite a database access library. Thanks to all!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top