473,657 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LINQ Newbie

I am trying to get into LINQ. I have created ConsoleApplicat ion
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\da ta\northwnd.mdf ");
Table<CustomerC ustomers = db.GetTable<Cus tomer>();
var query = from cust in Customers where cust.City ==
"London" select cust;
foreach (var cust in query)
Console.WriteLi ne(string.Forma t("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 1079
Well, Table<Customerc ould 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...@g mail.comwrote:
Well, Table<Customerc ould 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 "DataContex t" (rather than
"SomeSpecificDa taContext") 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 (ColumnAttribut e 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
1306
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. I tried the following query var results = from e in emp.employee where e.employeeRowParent.name == "Doe" select e;
10
1203
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, "Bundaberg")); Persons.Add(new Person("Cathryn", 36, "Perth"));
9
2499
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 about vs2008? is it different name space or framework for linq xml or linq sql? ( 2. do we need to have references to what linq's dlls. or namespaces? system core? 3. what name spaces are needed?
0
2357
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 occuring enough to be a real cause for concern. The errors occur a couple times a week and the website is hit with constant traffic 24x7. Below are the two errors that are encountered. I had read something about MARS causing errors like this but...
5
1151
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 productGroups = from p in products group p by p.Category into g where g.Group.Any(p =p.UnitsInStock == 0) select new { Category = g.Key, Products = g.Group };
1
2591
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 items where name == x.Name select x).First(); // Work on item } Is there a way to make that query more efficient? (My assumption is
3
12429
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: ====================== Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean TryCreateKeyFromValues(System.Object, V ByRef)
2
2755
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> <Parent>Table</Parent>
0
1072
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 (think about creating a sql report); I would like to save and reload the query, and I'm trying to implement it as a LINQ query. Is there any way to do this? Thanks,
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.