I search a way to create query by using a dataset as database simulator.
The dataset contain each table with primary key column. It also have foreign keys.
simulate database vb.net
I search a way to create the “Where” part by giving a list of Key/Value.
The dataset will be empty, its only a way to create an exponential list of query.
Sample:
sample:
Table A
colA
And
Table B
colB
colD
linked by
Table C
colA
colB
and
Table D
colD
I give the list
[colA] 1
[colA] 2
[colA] 3
[colB] 5
[colB] 6
[colD] 8
I want a query of every item on Table A containing element specified in the list.
Select *
from TableA
where colA in (1,2,3)
and colA in (
select colA
from TableC
where colB in (5,6)
and colB in (
select colB
from TableB
where colD in (8)
)
)
So I’m searching an algo to create the query. like any query generator working.
I can want data from any of those tables.
this of a function
function GetSubQuery(table, list(of keyValue) as string
my sample ask for TableA. but I can want TableB or C or D. with the same id List.
Situation (simulation)
I want table A,B or D.
I can ask for table A, giving id from colD.
I can ask for table A, giving id from colB.
I can ask for table A, giving id from colA.
I can ask for table A, giving id from colB and colD.
I can ask for table A, giving id from colB and colA.
I can ask for table A, giving id from colB and colD and colA.
I can ask for table B, giving id from colD.
...
we have here 18 possibilities.
But I dont want a query for the max possibilities and use it for every possibilites.
I mean the query for “table A, giving id from colB and colD and colA.” should not be use if you only have id from colA.
Because it can have a lot of data in the other table and you will search inside without needed.
the algo need to know, if you dont need to go there, you dont.
DataSets and DataTables do not support TSQL.
TSQL pretty just talks to a database engine.
You can define PK, PK FK relationships, and walk those relations.
Navigating DataRelations
You can cast to List and use LINQ to query.
LINQ (Language-Integrated Query)
Or you can just iterate the rows and do equality comparison.
SQL CE is an embedded database that supports TSQL.
Another option is XML and use LINQ to query the the XML.
Personally I would do this with classes (not DataSets) and overrite gethashcode and equals.
DataSets are heavy and slow and collection have come a long way in .NET.
Use HashSets (or Dictionary of KeyedCollection) for the collections.
Even have class TblATblD that represents the join and use HashSet.
If your ID can be Int16 then you can pack the two Int16 into Int32 on TblATblD.
I do this with Users Groups and then a UrsGrp.
User can see certain Fields.
Queries kind of like what you are talking about all in LINQ.