views:

64

answers:

2

I was reading about ORMs and one of the descriptions I read said that the ORM interacts with database metadata.

Why is this important or relevant?

Metadata, as I understand, is just a way of describing what the database contains. So, for example, the database might have an internal table that lists what user tables have been created. Why would something like this be useful to an ORM?

+3  A: 

The ORM uses the metadata to generate the code used to access the tables. For example, if it's a date column then it generates the code to deal with that column as a date.

It will read foreign keys and primary keys to build relationships in the code as well as for generating the proper SQL syntax.

This is just a few of the ways it uses the metadata.

klabranche
I see. So, as in your example of a date column, the ORM needs the metadata to determine exactly what 'type' of date column to translate the domain model to - e.g. DateTime, Date, Timestamp.
mihai
Exactly! You got it. :)
klabranche
@mihai +1 for you. :) Happy learning!
klabranche
Awesome. Thanks.
mihai
I just found this:http://davybrion.com/blog/2009/08/build-your-own-data-access-layer-series/It's from a contributer of NHibernate, who loves NHibernate but was in a situation where they had to for a client. It has some good insight into a simple DAL that uses Metadata to do some of the "lifting" for you.
klabranche
+3  A: 

What this means is that the ORM maps the schema, or structure, of the database to objects. Typically, this means mapping tables to classes (User table to User class), fields to attributes (Age field to User.Age attribute), and each record then represents an instance of that object.

Soviut
Right. So in the case of field-to-attribute, whether it's a VARCHAR or INTEGER will detmine what the type of the attribute will be when it translates it for the corresponding class instance.
mihai