Accepted answer

let's say i want to write a c# expression and a c# statment where i have a table in sql server named products and i want to pull all rows where price is greater then 50. how would yo write it?

linqpad builds the typed datacontext for you automatically, so you don't need to instantiate anything. in c# expression mode, just type the folowing:

products.where(p => p.price > 50)

and press f5. alternatively, you might prefer to use a query expression:

from p in products
where p.price > 50
select p

in c# statements mode, you'll need to call the dump() method to tell it to write out the results. you'll also need to terminate the expression with a semicolon:

products.where(p => p.price > 50).dump();

there are more examples in the samples section of linqpad - look at the 5-minute induction.


check out: which will give you an introduction to linq and using lambda expressions.

then have a look at which will give you the basics, but to answer your specific question:

var products = db.products.where(prod => prod.price > 50);
foreach(var product in products)
     //do something


var db = new mydatabasecontext();  // your database context.
var result = db.products.where(q=>q.price > 50);

...where db represents your orm context. price represents your mapping to the price field in the database. result represents the result set -- your database rows/entities.


just wanted to add - linq pad pluralizes - i did not know this and it drove me crazy for a good fifteen minutes

i was trying to select from a table called dentalapplication

    dentalapplication.where(a=> a.packageid > 0)

gave me this error

    'linqpad.user.dentalapplication' does not contain a definition for 'where'

changed it to

    dentalapplications.where(a=> a.packageid > 0)

and it worked

Related Query

More Query from same tag