How to get relational data into an object?

  • Thread starter Thread starter deko
  • Start date Start date
D

deko

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 of cfgObjects
_DateTime
_Integer

the cfgObject looks like this:

_stringCfgName
_ArrayList1 of strings
_ArrayList2 of strings
_bool1
_bool2

The data that initializes these objects is stored in a typed DataSet with
constraints and relations.

I suppose I could populate a DataTable and iterate through it in the
object's constructor but, as a newbie to C#, my guess is there's some
pattern or practice out there, or even some class in the FCL, that has a
better way.

Is there a standard (or better) way to get an object from relational data?

Thanks in advance.
 
Google for C# ORM or OR/M - object-relational mapping, and "entity objects",
and the like.
There's a lot to cover! If sure people will chime in with their favorite
methods and products...

m
 
Hello deko,

Just to add to Mike post abt O/R mapping I recomend to use NHibernate and
CodeSmith with 3rd-party templates
See Example of building DAL is over there http://community.codesmithtools.com/blogs/tutorials/archive/2006/02/13/nettiers.aspx

d> Is there a Pattern or best Practice for getting relational data out
d> of a database and into an object?
d>
d> The object in question has public properties that look like this:
d>
d> _stringName
d> _ArrayList of cfgObjects
d> _DateTime
d> _Integer
d> the cfgObject looks like this:
d>
d> _stringCfgName
d> _ArrayList1 of strings
d> _ArrayList2 of strings
d> _bool1
d> _bool2
d> The data that initializes these objects is stored in a typed DataSet
d> with constraints and relations.
d>
d> I suppose I could populate a DataTable and iterate through it in the
d> object's constructor but, as a newbie to C#, my guess is there's some
d> pattern or practice out there, or even some class in the FCL, that
d> has a better way.
d>
d> Is there a standard (or better) way to get an object from relational
d> data?
d>
d> Thanks in advance.
d>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
deko said:
CodeSmith sounds great (it ought to be for 100 bucks).

Is that all it is? You're getting off cheap...
Any tool is worth many times that if it works well for you and saves time --
even at 100 times that price you're still talking about 1% of a USD
programmer year, so the ROI should be there if it actually gets used.
 
What is the difference between UML and ORM ?
ORM is a replacement of UML ?
 
UML is a method for describing what a program should do. It's a
"modeling language", where "language" in this case means diagrams as
well as words.

ORM is a mechanism for getting objects in and out of a relational
database. An ORM is either a piece of software that mediates between a
database (relational view) and objects, or a design for such a piece of
software.

UML is a particular way of scribbling on the whiteboard (or writing in
documents) to tell other architects and programmers what you think your
program needs to do. An ORM is a piece of software you buy or build,
or, more loosely, a design for a particular piece of software you could
build. So, UML and ORM really don't have much to do with each other,
except for the (trivial) connection that you could use UML to specify
how your ORM should work.
 
UML is a method for describing what a program should do. It's a
"modeling language", where "language" in this case means diagrams as
well as words.

ORM is a mechanism for getting objects in and out of a relational
database. An ORM is either a piece of software that mediates between a
database (relational view) and objects, or a design for such a piece of
software.

UML is a particular way of scribbling on the whiteboard (or writing in
documents) to tell other architects and programmers what you think your
program needs to do. An ORM is a piece of software you buy or build,
or, more loosely, a design for a particular piece of software you could
build. So, UML and ORM really don't have much to do with each other,
except for the (trivial) connection that you could use UML to specify
how your ORM should work.

Thanks for the nice clarification.
 
CodeSmith sounds great (it ought to be for 100 bucks).
Is that all it is? You're getting off cheap...
Any tool is worth many times that if it works well for you and saves
time -- even at 100 times that price you're still talking about 1% of a
USD programmer year, so the ROI should be there if it actually gets used.

So how long have you worked for CodeSmith ;)
 
CodeSmith sounds great (it ought to be for 100 bucks).
Is that all it is? You're getting off cheap...
Any tool is worth many times that if it works well for you and saves
time -- even at 100 times that price you're still talking about 1% of a
USD programmer year, so the ROI should be there if it actually gets used.

Yes, but is the ORM component in CodeSmith any good?

I found ORM.NET:

http://sourceforge.net/forum/forum.php?forum_id=403142

Which is a free opensource tool.

Another reason CodeSmith may be worth the money is support.
 
deko said:
Yes, but is the ORM component in CodeSmith any good?

FWICT, Codesmith does not have an "ORM component", per se.
Codesmith, in conjunction with a 3rd party template, can generate
data-access layer classes for you from an existing database.
In addition, the template generates a set of CRUD functioality classes that
let you deal with those entities.
This is probably fine for many uses.

A more full-featured ORM system would allow more control over table/object
relationships, allow choice of various caching schemes, the abilty to work
"forward" from classes to database schema as well as "backward" from the
database to objects, the ability to deal with natural keys rather than just
ID's, allow various ways to map from DB relationships to objects, etc.

To the last point, ORM falls into two main camps, depending on what you want
to do:
(A) Do you want a backing-store (persistence) for existing classes? In this
case you're using an RDMS as a object database.
or
(B) Do you want "object access" to an existing, transactional RDMS? In this
case you're using objects to conveniently represent existing database
relationships.

Products exist to serve each (and sometimes both) puposes. This is a huge
topic to which I have only waded in as deeply as I needed to -- seaches
should provide you with plenty of info.

m
 
Yes, but is the ORM component in CodeSmith any good?
FWICT, Codesmith does not have an "ORM component", per se.
Codesmith, in conjunction with a 3rd party template, can generate
data-access layer classes for you from an existing database.
In addition, the template generates a set of CRUD functioality classes
that let you deal with those entities.
This is probably fine for many uses.

A more full-featured ORM system would allow more control over table/object
relationships, allow choice of various caching schemes, the abilty to work
"forward" from classes to database schema as well as "backward" from the
database to objects, the ability to deal with natural keys rather than
just ID's, allow various ways to map from DB relationships to objects,
etc.

To the last point, ORM falls into two main camps, depending on what you
want to do:
(A) Do you want a backing-store (persistence) for existing classes? In
this case you're using an RDMS as a object database.
or
(B) Do you want "object access" to an existing, transactional RDMS? In
this case you're using objects to conveniently represent existing database
relationships.

Thanks for the detailed reply.

I think I want door number B.

What I have is a big typed dataset with lots of relational data - from
whatever database. Rather than spin my own code to flatten out all that
data to initialize my objects, I want something that does it for me. AFAIK,
an ORM tool is the way to do this.
 
deko said:
Thanks for the detailed reply.

I think I want door number B.

I beleive this is the more common case. (Really more "ROM" than "ORM" - but
I guess that acronym would be confusing...)
What I have is a big typed dataset with lots of relational data - from
whatever database. Rather than spin my own code to flatten out all that
data to initialize my objects, I want something that does it for me.
AFAIK, an ORM tool is the way to do this.

If you have typed datasets, then you are already "objectifying" the database
to some degree.
I beleive (but am not sure of) that your new-fangled typed datasets will not
be used through most ORM solutions - the point would be to lose the dataset
as your access/update method all-together in favor of a normal set of
interconnected objects -- of course, how "connected" they are depends on how
deeply loaded your object-graph is. (Although a dataset, typed or not, *may*
be used under the hood, you wouldn't access it unless you needed an "escape"
mechanism.) But you should really look at specific mapping solutions to see
if they suit your needs.

m
 
Check out DevForce from IdeaBlade (www.ideablade.com). It is an
application-building tool that includes a ORM piece. The ORM code
includes lazy instantiation, object relationships exposed as
collections, off-line capability, and more. For my money and time, it
is much better than trying to build all that functionality on your own.
For large projects/companies, it may be worthwhile to build your own
framework (with something like CSLA and your own CodeSmith templates to
generate the code). But, if you really just want to get into your
application, try DevForce. It also handles other important parts of the
application, like bi-directional data-binding, user security, n-tier
architecture, and more. (Note: their target is WinForms applications -
aka Smart Client apps. Not targeting web apps as much.) I'm a satisfied
client.

Their Express product is free and handles client-server architecture
and a SQL Server database back-end. We currently use the commercial
client-server version with an Informix back end. We will be trying the
n-tier version (with their Business Object Server) on VS2005 soon.

User group, though still small, is at www.ibrunner.com. Grwoth has been
good in the last couple months.

Depending on your back-end, some of the open source frameworks or ORM
tools (eg. nHibernate) might work. When I looked they were not
production-ready and/or did not have connections to Informix. Most seem
to be ports of more mature Java frameworks.

Someone may also suggest the Data Access Application Block (part of
Enterprise Library) from Microsoft's Patterns and Practices Group. The
first version supported only SQL Server (shocking, I know). I also
found the application blocks to be overly complex.
 
deko said:
Thanks for the detailed reply.

I think I want door number B.

What I have is a big typed dataset with lots of relational data -
from whatever database. Rather than spin my own code to flatten out
all that data to initialize my objects, I want something that does it
for me. AFAIK, an ORM tool is the way to do this.

Then I'd check out LLBLGen Pro, http://www.llblgen.com
(note: I'm affiliated with this product)

- the most powerful code generator engine today
- strong o/r mapping functionality

FB

--
 
deko said:
Yes, but is the ORM component in CodeSmith any good?

I found ORM.NET:

http://sourceforge.net/forum/forum.php?forum_id=403142

Which is a free opensource tool.

Another reason CodeSmith may be worth the money is support.

ORM.NET is discontinued for a long time now.

Btw, 'ORM' isn't the proper acronym. ORM is the acronym for Object
Role Modelling (http://www.orm.net), you should refer to O/R mapping :)

To familiar yourself a bit what the possibilities are, feel free to
read my article: to O/R map or not to O/R map:
http://weblogs.asp.net/fbouma/archive/2004/10/09/240225.aspx

also, check out my ppt sheets I made some time ago about what O/R
mapping is:
http://www.xs4all.nl/~perseus/DataAccessAndORMapping_en.ppt

FB

--
 
ORM.NET is discontinued for a long time now.
Btw, 'ORM' isn't the proper acronym. ORM is the acronym for Object
Role Modelling (http://www.orm.net), you should refer to O/R mapping :)

To familiar yourself a bit what the possibilities are, feel free to
read my article: to O/R map or not to O/R map:
http://weblogs.asp.net/fbouma/archive/2004/10/09/240225.aspx

also, check out my ppt sheets I made some time ago about what O/R
mapping is:
http://www.xs4all.nl/~perseus/DataAccessAndORMapping_en.ppt

Thanks for the tip. I'll take a look.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top