Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 878
  • Last Modified:

Linq to sql , dbml - query

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
TrialUser
Asked:
TrialUser
2 Solutions
 
james-ct16Commented:
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
 
Fernando SotoCommented:
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
 
TrialUserAuthor Commented:
thanks
0

Featured Post

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now