473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

object/relational mapping

Hi,

I'm new to .NET and am trying to take advantage of the
object structure while accessing relational databases.

I started a small project for managing "projects". Here is
a description of my data structure :

A project would be made of tasks, and each task can
contain sub-tasks, so I would have something like
- Project1
- task1
- subtask A
- subtask B
- task 2
- Project2
...
(each line being a task).

Then, each task can "depend" on others : it could only
start when all the tasks it "depends on" are performed.
For instance : Project1/task2 "depends on"
Project1/task1/subtaskA.
So I end up with the following datamodel :

[Table "TASKS"]
int id_task [key] : unique identifier of the task
string name, description : ...
int id_parent : identifier of the parent task

[Table "TASK_RELATIONS"]
int id_task_1 [key] : identifier of the "preceding" task
int id_task_2 [key] : identifier of the "following" task
(the one that can only be started once id_task_1 is done).

And (here comes the problem), I would like to have an
object structure close to the following (I describe each
type ; "+" indicates a public property or method of the
described type) :

public static "MyApplication" : "global" container object.
+ TaskCollection "Projects" {get;} : collection of all
the top-level tasks (id_parent=0).
+ TaskCollection "AllTasks" {get;} : collection of all
the tasks.

public TaskCollection : a collection of "Task"s.
+ Task this[int index] {}

public Task : a task
+ int ID (this one might not even be useful as a public
prop)
+ string Name, Description : ...
+ string FullName {get;} // returns the concatenation of
this task and of all its
ascendants : "Project1/task1/subtaskA" for instance.
+ Task Parent {get;} // returns the task's parent task.
+ TaskCollection Children {get;} // returns a collection
with all the children tasks
+ TaskCollection PrecedingTaks // returns the tasks that
must be completed before this task can begin
+ TaskCollection FollowingTask // returns the task that
can begin once this one is done.

MyApplication contains also a "Data" property that is a an
object holding my 2 DataTables (MyApplication.Data.Tasks
and MyApplication.Data.Task_relations).

My BIG question is : how do I operate the mapping between
the two (the DB data model and the Object structure) ?

To have you better understand the requirements of my
model, here is a description of a "Projects" Form I
already started to write to allow the user to edit the
projects :
It contains a tree on the left (that uses
MyApplication.Projects to display all the tasks), and
a "detail" pane on the right. The detail pane is bound to
MyApplication.AllTasks, and the position of the
BindingManager is set by the Tree when the user clicks a
task.
The pane on the right contains standard controls
(TextBox "txt_Name", with property Text bound to "Name")
and some more complex controls
(ListBox "lst_preceding_tasks" with property DataSource
bound to "PrecedingTask").

Here are the first conclusions I could draw from reading
the documentation :

- for my "Tasks" to be bindable and editable in Windows
Forms, TaskCollection should implement IBindingList, and
Task should implement IEditableObject.

- I wanted to extend the DataView and DataRowView classes
as follow :
Task : DataRowView {}
TaskCollection : DataView {}
and make them "point" to the MyApplication.Data.Tasks
DataTable.
I had to give up as I saw that DataRowView cannot be
inherited (problem with the constructor, which is
internal, or something like that... [could you inherit
it ?]).

- Finally I tried to write to new classes "containing" the
DataRowView and DataView classes :

public class Task : IEditabledObject {
private DataRowView row;
public Task (DataRowView aRow) {
row = aRow;
}
public string FullName {...}
...etc.
}

public class TaskCollectoin : IBindingList {
private DataView view;
public TaskCollection (string filter) {
view = new DataView (MyApplication.Data.Tasks,
filter, "", DataViewRowState.CurrentRows);
}
... (implementation of some of the IBindingList
interface methods and properties) :
object AddNew() {
return new Task(view.AddNew());
}
object this[int index] {
get {
return new Task (view[int]); // what do you
think of this ?
}
}
... (mapping of ALL other methods and properties on the
view object) :
bool IBindingList.AnyProperty { get{return
view.AnyProperty;}}
...
}
What do you think of this solution ? Is it the right way
to do it ?

Here is a first problem, to begin with :
"Linking" a TaskCollection to a DataView of
MyApplication.Data.Tasks is OK as long as I want to use it
to edit the tasks. So for MyApplication.Projects it is
fine. I can Add Tasks to the Collection, it will insert a
new row in my "Tasks" table.
But for the "Children" or "PrecedingTasks" properties of
the Task object, the collection should rather be linked to
the MyApplication.Data.Task_relations table. Adding a Task
to the collection should insert a row in
the "Task_relations" table !
Should I have two different objects ?
For instance a TaskCollectionBase object, and one
extension of this class per type of collection I need ?
(PrecedingTaskCollection and FollowingTaskCollection would
point to the same table, but adding a Task to them would
insert a row with id_task_1=this.row[id_task] for the one
and with id_task_2=this.row[id_task] for the other).

Well, thank you very much for any hint, piece of advice,
or comment.
Please tell me if you know of any documentation on that
topic, or forums more specifically dealing with that kind
of problems...

Thanks again !
Olivier.
Nov 22 '05 #1
0 963

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mikey | last post by:
Hi all. In the process of trying to figure this thing out, I've been doing the old "stand around in the store and read as much as possible before you look like a derelict" thing. This time, with...
0
by: Olivier Jullian | last post by:
Hi, I'm new to .NET and am trying to take advantage of the object structure while accessing relational databases. I started a small project for managing "projects". Here is a description of...
2
by: object-relational persistence mapping | last post by:
Someone can tell me where I find a good Object-Relational Mapping library.
5
by: DraguVaso | last post by:
Hi, I'm ne to this subject, and has been looking around for some software that does the Object-Relational-Mapping, and generates the Data Access Layer. I found alreaddy a lot of application that...
17
by: deko | last post by:
Is there a Pattern or best Practice for getting relational data out of a database and into an object? The object in question has public properties that look like this: _stringName _ArrayList...
3
by: PeterMoris | last post by:
There are plenty of Object to relational mapping tools available in the market, but we don't know the strengths and weaknesses of each. Let’s share our experiences with O/R mapping products to the...
3
by: pratham | last post by:
If i understand correct? is strong typed DataSet is ORM implementation by Microsoft? Expecting comments .. please Praveen
4
by: AliRezaGoogle | last post by:
Dear members, Hi. I am really confused about object-relational mapping (ORM) softwares frameworks designed for .Net. For example I've read some about NHibernate and Spring.NET. Some others like...
4
by: Eric Savage | last post by:
Object relational mapping, for those who don't know, is a modern software concept for tools that automatically copy data across from your objects in code to database tables, or vice versa. ...
13
by: sulyokpeti | last post by:
I have made a simple python module to handle SQL databases: https://fedorahosted.org/pySQLFace/wiki Its goal to separate relational database stuff (SQL) from algorythmic code (python). A SQLFace...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.