Click here to Skip to main content
15,890,982 members
Home / Discussions / Database
   

Database

 
QuestionWrite to text file from a sql server stored-procedure Pin
flippydeflippydebop30-Oct-06 20:48
flippydeflippydebop30-Oct-06 20:48 
AnswerRe: Write to text file from a sql server stored-procedure Pin
flippydeflippydebop30-Oct-06 22:38
flippydeflippydebop30-Oct-06 22:38 
AnswerRe: Write to text file from a sql server stored-procedure [modified] Pin
flippydeflippydebop30-Oct-06 22:40
flippydeflippydebop30-Oct-06 22:40 
Questioninserting values from select query Pin
dj.rock30-Oct-06 19:46
dj.rock30-Oct-06 19:46 
AnswerRe: inserting values from select query Pin
neilsolent31-Oct-06 0:54
neilsolent31-Oct-06 0:54 
QuestionHow to store an 1:N tree (Hierarchy) Pin
peterchen30-Oct-06 14:52
peterchen30-Oct-06 14:52 
AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Colin Angus Mackay31-Oct-06 4:37
Colin Angus Mackay31-Oct-06 4:37 
AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Damodar Periwal31-Oct-06 9:46
Damodar Periwal31-Oct-06 9:46 
The following approach may be simpler. Model your object with a parent and a list of children relationship. Then use an Object Relational Mapping product like NJDX to easily retrieve any objects along with all their children without writing a single line of SQL in your application. For example,

You may define a (C#) class MyEntity as follows:

public class MyEntity {<br />
    int id; <br />
     int pid;            // id of the parent entity<br />
     ArrayList children;  // list of children<br />
     String name;<br />
     // other fields<br />
}


Then declaratively define the object relational mapping as follows:

CLASS MyEntity TABLE MYENTITY<br />
      PRIMARY_KEY id<br />
      RELATIONSHIP children REFERENCES ChildrenCollection WITH id<br />
;<br />
COLLECTION_CLASS ChildrenCollection COLLECTION_TYPE ARRAYLIST ELEMENT_TYPE MyEntity<br />
     PRIMARY_KEY pid<br />
;


Now, in your application, you can do a query like:
<br />
   String predicate = ....;  // WHERE clause for the top-level objects<br />
   ArrayList entities = njdx.query("MyEntity", predicate, ...);


NJDX will get the top-level MyEntity objects along with its children, each child will be fetched with its own children, each grandchild will be fetched with its own children and so on ... all of this with just one query call to NJDX.

The nice thing about such an approach is that it is much easier to deal with object-oriented data in your application. Further, you don't have to write the invariably complicated SLQ/ADO.NET code to fetch and properly associate all the children objects in a long hierarchy. You can also use NJDX to easily insert, update, and delete objects. Even cascading deletes can be done by specifying the mapping appropriately.

-- Damodar Periwal
Software Tree, Inc.
Simplify Data Integration

AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Eric Dahlvang1-Nov-06 11:31
Eric Dahlvang1-Nov-06 11:31 
QuestionMicrosoft Access VBA Question About ListBoxes... Pin
new_phoenix30-Oct-06 14:15
new_phoenix30-Oct-06 14:15 
QuestionSQL Select Puzzle Pin
neilsolent30-Oct-06 9:51
neilsolent30-Oct-06 9:51 
AnswerRe: SQL Select Puzzle Pin
Eric Dahlvang31-Oct-06 3:07
Eric Dahlvang31-Oct-06 3:07 
QuestionWhere can I lean about stored procedures? Pin
CCMint30-Oct-06 7:01
CCMint30-Oct-06 7:01 
QuestionCOPY TABLE giving unexpected EOF error Pin
Zeolite30-Oct-06 6:55
Zeolite30-Oct-06 6:55 
QuestionBest way to save data Pin
knappster30-Oct-06 1:43
knappster30-Oct-06 1:43 
QuestionADO.NET related question Pin
Imtiaz Murtaza30-Oct-06 0:57
Imtiaz Murtaza30-Oct-06 0:57 
AnswerRe: ADO.NET related question Pin
Colin Angus Mackay30-Oct-06 1:54
Colin Angus Mackay30-Oct-06 1:54 
GeneralRe: ADO.NET related question Pin
Damodar Periwal31-Oct-06 10:14
Damodar Periwal31-Oct-06 10:14 
AnswerRe: ADO.NET related question Pin
Hunuman30-Oct-06 2:02
Hunuman30-Oct-06 2:02 
GeneralData Type Issue in Where Clause Pin
Brady Kelly30-Oct-06 0:13
Brady Kelly30-Oct-06 0:13 
JokeRe: Data Type Issue in Where Clause Pin
Rob Graham30-Oct-06 3:14
Rob Graham30-Oct-06 3:14 
Questionselect query filling 2 typed datasets Pin
steve_rm29-Oct-06 22:10
steve_rm29-Oct-06 22:10 
QuestionPurpose of SQL Server Jobs Pin
King Shez29-Oct-06 19:50
King Shez29-Oct-06 19:50 
AnswerRe: Purpose of SQL Server Jobs Pin
Eric Dahlvang30-Oct-06 3:13
Eric Dahlvang30-Oct-06 3:13 
Questionconnection cannot be made? Pin
Haoman1729-Oct-06 0:48
Haoman1729-Oct-06 0:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.