tags:

views:

662

answers:

10

I would like to be able to use a Dataset as an in-memory datastore. I want to be able to use SELECT, INSERT, UPDATE, and DELETE, CREATE TABLE, DROP TABLE, ALTER TABLE ADD COLUMN, ALTER TABLE DROP COLUMN, and support for Constraints PRIMARY KEY, UNIQUE, NOT NULL, FOREIGN KEY, REFERENCES.

A: 

Sorry, that's not what a DataSet is for.

Why do you want to do this?

John Saunders
Who says that's not what a DataSet is for? The DataSet has a complete object model, well known interface, designer support, and Debug Visualizers available. Why would I re-invent the wheel to display the information about a "DataSet" when one exists?
JJS
Who says? The past seven years of experience in using it, and reading what Microsoft and anyone else says about it. Nobody has ever suggested a DataSet be something to issue queries against. Filter and sort (using a DataView) yes, but not a general query platform. That's what SQL Server Express and Compact are for.
John Saunders
+2  A: 

This is .Net? What version? 3.5 and later let you run sql-like linq queries on any IQueryable

Joel Coehoorn
Yes. DataSets aren't available in any API I know of except for .Net.IQueryable does not support the notion of modifying the schema of an object. Please correct me if I'm wrong, but Linq does not define any query operators to manipulate the schema of queried objects.
JJS
Who voted this up when this person didn't even RTFM on the capabilities of standard query operators and their capacity to modify the structure of an object definition. Yes there's projection operators, but that's hardly the same as SQL's DDL grammar.
JJS
+2  A: 

Sounds like you need an in memory database, not a dataset.

Cody C
see clarification comment. I would be happy to use an in-memory database if they provide a complete object model which has a very similar API to the DataSet for interrogating the structure of the database. God suggestions?
JJS
who voted this up when Cody couldn't even make a recommendation of an in-memory database with a .Net API?
JJS
+2  A: 

If you want to test your database commands on an in-memory data store, DataSet is not the way to go, as its not an in-memory relational database engine. As others have said, you can do all sorts of querying on a DataSet, but not DDL commands. I have looked at various in-memory or embedded database engines (SqlLite, HSQL, Firebird) but never came close to finding a good way to unit test Sql Server code in memory, generally due to the limitations of those engines (e.g. no stored procedures).

If you need an embedded database for your application, have a look at those products. If you need to test Sql Server commands, you'll have to run them on an instance of Sql Server (consider Express, lightweight and free).

Matt Howells
I do not want to test my DDL commands on on in-memory store. I was more focused on using a well defined grammar that sql provides to manipulate the DataSet instance.
JJS
Then you should update your question to say you don't actually care about the grammar, that it's just an example of the API you need.
John Saunders
+1  A: 

The short story is that you can't do those operations on a DataSet or any other .NET datatype. Those commands aren't inherent in the data itself, they're part of database software supporting SQL; you can only use those operations with software that supports them like a database server or embedded database.

Depending on what your are doing, linq may be useful, but doesn't provide exact SQL syntax or any of the specification language bits you mentioned. (ALTER TABLE, etc.)

If your project is not already using an external database, you could also consider using an embedded database (sqlite, Firebird, not sure what else).

Jesse Millikan
I know that you cannot do those operations nativly on a DataSet instance. I asked if anyone knew of a supplemental API that was capable of doing the operations.
JJS
+1  A: 

you want LINQ! It can perform all the actions you asked for upon your data ... and far more whilst giving you that sexy feeling that it probably shouldn't be that easy.

It will rock your box (if you are used to ado.net anyway)

Also look at Linq2SQL as it offers a little more when it comes to writing/reading your in memory data back to a database ... or linq2xml if you want to use a webservice.

John Nicholas
I must have missed the Linq operator that lets me add or remove a column from a table. Could you please send a URL to the MSDN documentation on what that Method is?
JJS
dude, use google, read some tutorials, its not like an answer on here will stop you from working. Also some of your replies have been rude, doesn't make me want to spend time hunting around for you. People on here are trying to help you based on what you told them.
John Nicholas
A: 

You can't because the DataSet is an in-memory representation on the client-side of the data that you retrieved.

It is also agnostic to the provider of that data. Because of that, you can't use the same syntax as you would against the data source that the data came from.

The DataSet has it's own syntax for filtering data, but it is not heavily based on SQL.

Rather, you should use LINQ to DataSets which will give you a more-SQL-like experience in querying your data in a DataSet.

casperOne
A: 

If you don't want to use LINQ (.NET 2.0 for example), there is a "select" method that allows you to provide a filter with "where-clause-like" syntax. Here's an MSDN link:

http://msdn.microsoft.com/en-us/library/system.data.datatable.select

This is a DataTable method so I don't know that it provides all that you're looking for. Also, this only allows you to select a subset of your dataset, not perform updates/inserts/deletes.

Mark
A: 

You may want to consider using temporary tables. Or even standard tables if your data has to be shared between database connections.

If you are looking for in-memory datasets for the speed they provide, you may want to look at in-memory table storages (MySQL and PostGreSQL do it, and others can be tricked into doing it by setting the table storage space on a ram-disk for instance).

Short-lived tables are often overlooked, but they are actually very helpful.

Nicolas
A: 

Someone has made this a reality in the form of a commercial product. http://www.queryadataset.com It supports all of the features that I originally asked about http://www.queryadataset.com/Documentation/Expressions/tabid/80/Default.aspx.

JJS