SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)

    Arrow Here's a challenge for you all.

    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.

    Let's see what you can do.

  2. #2
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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!

  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Glad to see there's some interest! =)

    Ok, I'll make it a little easier for you guys, and give you a hint as to where to start.

    - Only concern yourself with SqlServer output.

    - Only concern yourself with select statement generation.

    Hint:

    Given the following code, you should be able to build what you want.

    var query = new List<Customer>().Where(x => x.IsActive == true).AsQueryable();

    var expression = query.Expression;

    Good luck!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •