frenchie
frenchie

Reputation: 51997

building a testpage with user-customizable linq-to-sql query

I need to show the database tables to a tester. For now, I have hard coded the queries that show the data of each table: the user clicks on a list of tablenames and the server returns a gridview with all the data for that table. The queries are pretty simple:

var AllTheTable = (from t in MyDataContactTableName
                   select t).ToList();

I want to add a textbox where the tester can enter a custom linq-to-sql query at runtime.

How can I do this?

Thanks.

Upvotes: 0

Views: 72

Answers (2)

everag
everag

Reputation: 7672

My advice is to not reinvent the wheel and show him LINQPad :)

http://b.roozz.com/apps/61/LINQPad.htm

LINQPad example

Upvotes: 1

Chris Shain
Chris Shain

Reputation: 51359

Linq doesn't work like SQL- you need to run linq-to-sql queries through the compiler, because they are ultimately compiled C# code. Why not just give your users the ability to run a SQL query? There are a lot of security pitfalls around what you are asking either way, but with just SQL they can only mess up your database. With linq-to-sql they could potentially compromise your web server.

If this is an internal project where security isn't a concern and you just want to give the tester arbitrary access to your SQL data, have them write SQL.

Upvotes: 2

Related Questions