tags:

views:

183

answers:

7

Which ORM will give me compile-tested queries?

Is linqtosql compile time tested?


Edit:

Say I write a query that references a column named 'TotalSales'. I then rename the column in my database to TotalSales2 (and any other config file like: Employee.cfg.xml in nHibernate).
When I compile the project, I want Visual Studio to tell me the column 'totalSales' doesn't exist and then I will go and change it.

+5  A: 

There aren't any as far as I'm aware. They will often let you create a LINQ query that cannot be translated into SQL for example. Also, I am not aware of any compile time checking that your mappings map to your database correctly.

You can, and should in my opinion, perform all these checks within tests. Most ORMs make this easy to do.

Garry Shutler
true, unit testing will solve the issue.
Blankman
+1 for unit testing. Becomes no issue after you do.
rball
Unit testing will do the job but it's only for run-time checks
vidalsasoon
+2  A: 

I use LLBLGen but it has to be "refreshed" when data model changes are made. I don't think you'll get an ORM that will AT COMPILE TIME check for modifications against the database. You're asking for quite a bit there.

Nick DeVore
+1 I agree code generation is the easiest solution, even though you have to re-generate the code if you change the database.
Bill Karwin
Tools that upgrade database structure according to domain model are also very effective.
Alex Kofman
A: 

SubSonic can do that if you include the code generation step as a pre-build event.

Ben Schwehn
+1  A: 

In DataObjects.Net properties marked by [Field] attribute are always bound to field in database, so you can be sure that query will be translated. If you use not persistent field or another not supported statement, query translator will fail in runtime or performs such operation on fetched objects (on client).

Generally compile time validation is impossible or theoretically can be performed with special post-build tasks, that will scan compiled code, find all queries and validate them. But such checks will seriously slow down compilation process.

Alex Kofman
A: 

I used a Java tool called DODS, which was developed ca. 2000 with the Enhydra application server. DODS is still around here: http://www.enhydra.org/tech/dods/

The way DODS works, and which meets your goal of compile-time validation, is that it's a code generation tool. It generates Java classes corresponding to the tables in your database. Object instances of these classes have getters and setters for each column in the table. Of course if you change your database structure, you have to re-generation the Java code using DODS.

As long as you keep the generated code up to date with the structure of your database, it provides compile-time validation that any application code that uses these classes is querying valid tables and columns.

Anyway, I realize you tagged your question with C# and ASP.NET. A tool that generates Java code isn't going to be that helpful for you. But there could be another tool more specifically for .NET that works on the same principle of generating code that maps to database structure. So I'd suggest narrowing your search to .NET ORM tools that say something about code generation.

Bill Karwin
+1  A: 

Perhaps not exactly what you're looking for but if using the Entity Framework and selecting "Update Model From Database" from the designer you will get messages saying the fields are no longer mapped if you change the names.

This doesn't happen automatically when you build a project.

vidalsasoon
+1  A: 

Basically, you need 2 features together:

  • Compile-time checked queries (= an ORM with LINQ implementation). This is normally not a problem - at least some tools support this.
  • Pre-build step updating your entities based on database schema. AFAIK this is rarely implemented this way - normally you must explicitly update the model by the schema. Note that this part is normally rather costly.
Alex Yakunin