Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting Started Using Linq in C# Web Application

Posted on 2010-11-30
8
Medium Priority
?
443 Views
Last Modified: 2012-05-10
I am programming a internal database web application in Visual Studio 2010 with C#/ASP.NET.  I am fairly familiar with SQL and ADO.net, but I would like to try LINQ because I've heard it can make my job easier.

I have succeeded in connecting to my database using ADO.net.  But I don't even know where to begin with LINQ.  LINQ doesn't use "connection strings," does it?

I've added a connection to my database in Visual Studio's "Data Connections" and I can see all my databases and tables.  And from my web searches it looks like I need to add some kind of reference to a "data context" to the database I want to access with LINQ, but how do I go about doing that?  Do I need to add something to web.config?  Or add a class to code behind...?  I've read about DBML files, is this what I need to generate?
0
Comment
Question by:KTN-IT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34239558
You need to create a Linq-To-Sql model, or an Entity Framework model, and then run your Linq queries against that.

This should help you get started:

    http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx
0
 
LVL 5

Author Comment

by:KTN-IT
ID: 34239664
I've looked at this page many times.  Am I supposed to find a "Linq to SQL" designer in Visual Studio?  Where might I find that?
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 34239719
Hi KTN-IT;

To your question, " LINQ doesn't use "connection strings," does it?", Linq does use a connection string. It uses by default the connection string that was created when you established a connection from Visual Studio IDE to the database. This can be changed by adding a connection string to the constructor of the datacontext when you instantiate one.

To your question,  "I've read about DBML files, is this what I need to generate?", You need to create a DBML file.

To create the model that maps the class in code to the columns in a database follow the steps in this article.

LINQ to SQL (Part 2 - Defining our Data Model Classes)
http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

Fernando
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34239735
Right-click your project, choose Add > New Item. In the dialog that appears choose, under Data, choose "LINQ to SQL Classes" or "ADO.NET Entity Data Model" depending on which you want to use.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 34239776
See the linq I posted above for how to use the designer.
0
 
LVL 5

Author Closing Comment

by:KTN-IT
ID: 34240456
Thanks again!
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 34240587
Did you read at all the link I post?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34240610
The link you posted was the same one i posted earlier!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question