I've been toying with the idea of using the core LinqToSql (System.Data.Linq.SqlClient) system to simply generate an sql statement. Without using a data context, or actually executing the query, it should be able to generate the statement and spit it out. An example might look like this:
var sql = SqlQuery<Customer>().Where(x => x.IsActive == true).ToSQL();
And that's pretty much it. It shouldn't run the query, or rely on an active connection or command, just build the tsql based on the model.
If you need to write your own IQueryProvider implementation, you may change the SqlQuery to accept it, but I think it should be possible without one.
You could not have picked a harder task . Generation SQL is one of the hardest things to do. I have a book that showed how to do the same thing with WebForms + ADO.NET, and it was waaaaaaay over my head. But, if I get some time I will at least attempt it. If we are going to have everyone in this forum to try, without prizes, thanks SP, lets start out with a smaller task and move up. Maybe I am slow, and some people here can do it. But, I think it will be cool to have challenges every now and then to show off our mad skills, then I'm with ya!
Bookmarks