Solved

Linq to sql , dbml - query

Posted on 2010-09-16
3
864 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 62

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now