Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

LINQ: problem obtaining data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
K Viltersten - 22 Feb 2008 18:52 GMT
I got me a DB called "deebee.sdf" and by

 DataContext db = new DataContext
   (@"C:\deebee.sdf");

i create connection to it. In there a table
called "tabula" resides. Now, the problem
is that i can't get any info from it. I've
tried to follow the tutorial on MS' site by

 var query = from tabula in db select tabula;

as well as

 IEnumerable<Object> query =
   from tabula in db select tabula;

but, as you surely expect, the compiler though
otherwise. I suspect that it's a matter of a
simple sytax confusion. Is it and if so how?

--
Regards
Konrad Viltersten
--------------------------------
sleep    - a substitute for coffee for the poor
ambition - lack of sense to be lazy
Jon Skeet [C# MVP] - 22 Feb 2008 19:07 GMT
> I got me a DB called "deebee.sdf" and by
>
[quoted text clipped - 16 lines]
> otherwise. I suspect that it's a matter of a
> simple sytax confusion. Is it and if so how?

As far as I'm aware, you can't do an awful lot with a "bare"
DataContext. You need to create a specific DataContext - most easily
done with the DBML designer in VS2008.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Nicholas Paldino [.NET/C# MVP] - 22 Feb 2008 19:10 GMT
Konrad,

   You need more than just a data context to access the underlying
database, you need to have classes that will map to the underlying tables in
the database.

   The easiest way to do this is to add a new LINQ to SQL classes file in
VS.NET which will give you a design surface which you can drag and drop
tables from your database onto.  From that designer file, classes will be
created which you can then use in your queries.

   You can also do this by hand, creating your own classes and mapping the
attributes in the table to various fields/properties.  Take a look at the
section of the MSDN documentation titled "Attribute-Based Mapping (LINQ to
SQL)", located at:

http://msdn2.microsoft.com/en-us/library/bb386971.aspx

   It will give you a good starting point if you want to do this by hand.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I got me a DB called "deebee.sdf" and by
>
[quoted text clipped - 22 lines]
> sleep    - a substitute for coffee for the poor
> ambition - lack of sense to be lazy
K Viltersten - 22 Feb 2008 19:36 GMT
> You need more than just a data context
> to access the underlying database, you
[quoted text clipped - 7 lines]
> fields/properties...
> http://msdn2.microsoft.com/en-us/library/bb386971.aspx

Yes, i've seen the description but i
disregarded it (obviously foolishly)
since i expected something far less
advanced, when only accessing a simple
database and performing a short query.

:(

Perhaps it's more appriopriate to
execute a standard SQL query. How does
one do that? I remember something about
sending in strings with SQL statements...

--
Regards
Konrad Viltersten
--------------------------------
sleep    - a substitute for coffee for the poor
ambition - lack of sense to be lazy
Nicholas Paldino [.NET/C# MVP] - 22 Feb 2008 20:49 GMT
Konrad,

   Did you not try the designer in VS.NET 2008 (I am not sure if the
Express Editions have it or not, or if you have a version of VS.NET that has
the designer).

   With the designer, it is really becomes a drag-and-drop operation.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>> You need more than just a data context to access the underlying database,
>> you need to have classes that will map to the underlying tables in the
[quoted text clipped - 22 lines]
> sleep    - a substitute for coffee for the poor
> ambition - lack of sense to be lazy
K Viltersten - 22 Feb 2008 22:17 GMT
> Did you not try the designer in VS.NET 2008.
> With the designer, it is really becomes a
> drag-and-drop operation.

I believe that i have the designer but when i
drag and drop my table into the area, i get
the error message telling me that the selected
object uses an unsupported data provider.

What i did was to create a new LINQ to SQL
object and try to drag-and-drop the table of
mine onto the empty region in the middle.

--
Regards
Konrad Viltersten
--------------------------------
sleep    - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.