473,320 Members | 2,048 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,320 software developers and data experts.

LINQ Newbie

I am trying to get into LINQ. I have created ConsoleApplication
project and have pasted in the code from one of the examples in help:

DataContext db = new DataContext(@"c:\program files
\microsoft sql server\mssql\data\northwnd.mdf");
Table<CustomerCustomers = db.GetTable<Customer>();
var query = from cust in Customers where cust.City ==
"London" select cust;
foreach (var cust in query)
Console.WriteLine(string.Format("id = {0}, City =
{1}", cust.CustomerID, cust.City));

But the compiler barfs on the second line. Apparently, the Customer
object is a "typed table". The example does not tell you how to create
this typed table.

I have searched help and cannot find any direction. Can someone point
me in the right direction?

Jun 27 '08 #1
3 1059
Well, Table<Customercould be (I guess) described as a "typed
table"... what is the *exact* error message?

Marc
Jun 27 '08 #2
On Jun 19, 4:50*pm, Marc Gravell <marc.grav...@gmail.comwrote:
Well, Table<Customercould be (I guess) described as a "typed
table"... what is the *exact* error message?

Marc
I called it a typed table because the example I pulled that code from
had a comment before thedeclaration of the Customers table object that
said:

// Get a typed table to run queries.

The build error I get is:

The type or namespace name "Customer" could not be found (are you
missing a using directive or an assembly reference?)

Actually, I get two of those for the two references to Customer in the
statement.

I am also wondering how this works since the actual table in the
database is named Customers, not Customer.
Jun 27 '08 #3
Well, you still need to define the Customer type; if you use the IDE
tools, this is drag'n'drop operation, but you can write LINQ-to-SQL
classes by hand too. Based on the "DataContext" (rather than
"SomeSpecificDataContext") I'd guess the example is following the
hand-crafted approach, so you definitely need to declare a Customer type
along with all the necessary metadata.

Re the type being Customer and the table Customers - this isn't a
problem; you can tell LINQ-to-SQL about this mapping in either the
attributes that are attached to the type (TableAttribute etc) and its
members (ColumnAttribute etc), or via a separate xml file. If you are
using the IDE tools, then you just tweak the properties in the designer
(which writes the "dbml" file), and it writes the suitable attributes
for you.

Marc
Jun 27 '08 #4

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

Similar topics

2
by: Satish | last post by:
Hi I an newbie to LINQ. I have a dataset with one table employee which has a self referencing foreign key manger id. I want to write a query to get all the employees under a particular manager....
10
by: damiensawyer | last post by:
Hi, I have the following code extract... ---top--- List<PersonPersons = new List<Person>(); Persons.Add(new Person("Peter", 28,"Perth")); Persons.Add(new Person("Matthew", 31,...
9
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how...
0
by: =?Utf-8?B?SHlwZXJjb2Rlcg==?= | last post by:
I'm encountering some strange behavior after deploying a ASP.net 3.5 website to production, i'm unable to reproduce these in my dev environment. This error seems to occur very randomly but it's...
5
by: Mike P | last post by:
Here is another one I hope somebody can help me with, this is the AnyGrouped example and does not recognise the 'Group' as being valid : List<Productproducts = GetProductList(); var...
1
by: DaveD | last post by:
Let's say I have a collection ("items") of objects that each have a "string Name" property. I understand I can create a loop like this: foreach (string name in names) { var item = (from x in...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
2
by: Simon Woods | last post by:
Hi I am struggling to navigate an XElement and I'm not sure what is going wrong. Here's my XML via vb's xml literals Dim l_testSchema = _ <Mappings> <Definitions> <ItemGroup>...
0
by: balint kardos | last post by:
Hi all, My question is about parsing and saving a LINQ query from/to xml. I'm creating an web interface where a user can select fields from dataset tables, and create relations between them...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.