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
Solved

Linq to sql , dbml - query

Posted on 2010-09-16
3
868 Views
Last Modified: 2013-11-11
Is it possible to write sql query inside the dbml context like we could do in the datasets wizards in the ado.net.
Or should the query be written only in the asp.net code?

any suggestions ould be great. thanks
0
Comment
Question by:TrialUser
3 Comments
 
LVL 10

Accepted Solution

by:
james-ct16 earned 250 total points
ID: 33691588
Howdy

The code should be written in linq. Remember the linq to sql translates the linq query to sql so you dont get all the data and parse it again. If you want to check this run the database profilers and look at the code generated.

Scott Guhrie gives a good worked example of this at http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx

Hope that Helps

James
0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 33692569
Hi TrialUser;

Although you can not write an sql query inside the dbml context you can execute a SQL query from inside your code by using the DataContext method ExecuteCommand the syntax is :

public int ExecuteCommand( string command, params Object[] parameters )

Documentation here
http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.executecommand.aspx

Fernando
0
 

Author Closing Comment

by:TrialUser
ID: 33795004
thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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