Dynamically built LINQ to SQL query without Entity classes

LINQ2SQL is pretty good. It is easy to create entity classes and use it.

but what if I don't know at compile time anything about a database and tables?

but I need to query the table "Foo" in "FooDb";

Can I run Linq queries on a database without any Entity classes?

Could you show me an example?

+3
source share
4 answers

Linq2Sql is an ORM - Object Relational Mapper .

Thus, he must know the database structure in order to create classes that you can interact with before compiling the application.

, , , Linq2Sql ORM, .


, , , , , .

+4

LINQ to SQL . , - , LINQPad. , . , LINQ, , ?

0

, .

( , -, ) , :

0

Ok. WebMatrix.Data?

If you need easy access to the database, and you do not want to be bothered by openings, closures, etc. And your project does not need strongly typed objects.

This is what Jeffrey Palermo showed at MVCConf. Piece of code:

using WebMatrix.Data;

...

public IEnumerable<dynamic> Execute(){

   Database db = Database.Open("EasyTimeTracking");
   var employees= db.Query("select FullName, Startdate, EndDate from Employee");
   return employees;

}

Is it enough to use the SQL material in C # instead of the old way? What do you think?

0
source

All Articles