C# Selections with SQL Syntax (Not LINQ!)(www.sharpregion.com)

submitted by AdrianAisembergAdrianAisemberg(2004) 3 months, 4 days ago

Select objects in C# with real SQL syntax. Give your users the ability to filter/select data during runtime.

2 comments |category: |Views: 234

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by dpetersondpeterson(4397) 3 months, 3 days ago 0

Now, I like having the ability to use SQL syntax, but is there a performance concern over loading the collection into a DataTable just to apply the filter? LINQ is lazy, wouldn't this require loading the entire collection into memory twice, then copying the values you want into another collection?

Reply

posted by AdrianAisembergAdrianAisemberg(2004) 3 months, 3 days ago 0

You are right. LINQ queries are lazy and perform better, but the queries are compiled and cannot be defined by a user during runtime (unless you parse the user's expression into a dynamic LINQ expression).

The collection is already in memory. It doesn't matter how do you run a query over it. Even if you run a lazy LINQ query on a collection - the collection is already there, the query itself is executed in a lazy way.

However, creating a DataTable and loading the data into it is an expensive operation. If you already have a way to parse user-defined expressions - I wouldn't recommend using the DataTable approach. I don't know of any way to parse such expression so I use DataTables in my projects (assuming the data is small).
You can take a look at my CLAP project: http://adrianaisemberg.github.com/CLAP/.
I use such a mechanism to parse user-defined validation expressions (here: http://adrianaisemberg.github.com/CLAP/#validation_expression).

The post is about a clever use of an old existing feature. It doesn't talk about the performance of it neither recommends it over LINQ.

Reply

information Login or create an account to comment on this story