473,394 Members | 1,742 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,394 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.
Jul 21 '05 #1
0 1251

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...
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...
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...
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.