473,379 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

LINQ and ToList when querying multiple sources

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?
Apr 9 '08 #1
3 8340
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
Apr 9 '08 #2
Marc S wrote:
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();

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 9 '08 #3
On Apr 9, 10:48*am, Marc Gravell <marc.grav...@gmail.comwrote:
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!
Apr 9 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: paululvinius | last post by:
Hi! Testing som Linq-expressions and tried to measure performance and compare it to pre-Linq programming. The folloing two methods are functional equal but the non-Linq one is twice as fast....
0
by: Marc Gravell | last post by:
Well, I'd have to wonder why you don't just use Dictionary<,/ SortedList<,/ SortedDictionary<,(and just use .Keys and .Values) But something like below: List<KeyValuePair<DateTime, double>list...
15
by: shapper | last post by:
Hello, I have two Lists: A = {ID, Name} = { (Null, John), (Null, Mary), (Null, Andrew), (Null, Peter) } B = {ID, Name} = { (1, John), (2, Robert), (3, Angela), (4, Andrew) } I want to...
2
by: shapper | last post by:
Hello, I have the following LINQ: List<Tagtags = (from t in database.Tags select t).ToList(); I need to restrict my results and for that I have two parameters: StartWidth and N
1
by: shapper | last post by:
Hi, On a form I have an input where tags are inserted in a CSV format. Then on my code I convert the CSV string to a List<Tag>. Tag is an object with two properties: TagID and Name So when I...
4
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I am trying to set up a dynamic search using linq. I believe the syntax is correct, but cannot confirm it because when I try to cast my Session from a List<to IQueryable<>, I get a cast error...
2
by: shapper | last post by:
Hello, I have the following Linq query: List<PostsTaginsert = (from t in (from t in database.Tags join p in paper.Tags on t.Name equals p.Name select t).ToList() select new PostsTag {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.