Re: Object-relational mapping tool

From: Alfredo Novoa (alfredo_at_ncs.es)
Date: 03/13/04


Date: 13 Mar 2004 10:15:07 -0800


"Daniel Parker" <danielaparker@spam?nothanks.windupbird.com> wrote in message news:<gHs4c.50669$6y1.1821089@news20.bellglobal.com>...

> >>You do not think that tools that automatically bind a SQL result set
> >>to the properties of an object are useful?
>
> > I can bind visual controls (objects) to database tables without any
> > tool or using the tools provided by the IDE. But it does not have any
> > relationship with object-relational mapping.
> >
> Uh, huh, and what if you were writing code as a creator rather than a user
> of visual controls?

Then it has even less relationship with object-relational mapping.

To create a new datagrid object for the .NET framework (for example),
does not have any relationship with the called O-R mapping.

> Mapping SQL result sets to instance variables is a big
> part of what object-relational mapping is about.

Agreed, but what I say is that it is a completely wrong way to map SQL
results to application objects.

> What does SQL have to do with opening and closing database connections?

SQL is the interface with a SQL DBMS.

> Have you never seen code like this before?
>
> Connection connection = DriverManager.getConnection(
> databaseUrl, user, password);
> connection.setAutoCommit(false);
> Statement stat = connection.createStatement();
> ResultSet resultSet = stat.executeQuery(sqlQuery);
> while (resultSet.next()) {
> // Do something;
> }
> resultSet.close();
> connection.close();

It is trivial to abstract this stuff into components. Again there is
no relationship with O/R mapping. You can do that in Visual Basic,
Delphi, Power Builder, etc.

> Now, if we added nested connections and transactions and error handling and
> binding the result values to instance variables, things would start to
> become interesting. There's nothing wrong with SQL, but most of the lines
> of code here are concerned with other things, and those are the things that
> should be the primary focus of OO-Relational binding.

No!

There is not anything wrong in the automation of the bindings between
the DBMS and the GUI. O/R mapping is not that.

O/R mapping consists in binding the database tables to main memory
network structures like:

class Customer {
   int ID;
   string Name;
}

class CustomerList {
  private ObjectList list;
  CustomerList() {list = new ObjectList();}
  public void Add(Customer customer) { list.Add(customer) }
  public void Delete(Customer customer) { list.Delete(customer) }
}

That is what is wrong.

> > With O-R mappers you hide a high level declarative interface (SQL)
> > behind a primitive procedural interface (3GL).
> >
> Does anything I've written above suggest that's what I do?

No, but O/R mapping consist in that and I am talking about O/R
mapping.

> > But the API is only a mechanism to submit SQL queries and to return
> > the results. It is not a very important issue.
> >
> In a data processing application written in C, C++, Java, etc., the number
> of lines of code to do these things could be very large.

It is one of the reasons because I don't use that languages. In Delphi
and Visual Basic the number of code lines to do these things is zero.

> And it's all
> stupid code. That's what object-relational mapping abstractions are, or
> should be, about.

We are talking about different things. O/R mapping is not that, O/R
mapping is a wrong way to do that, which consists in the creation of
superfluous main memory network structures (called business objects),
and in binding them to tables.

> Personally, I don't want to write a single line of code
> to put a date variable from a SQL result set into a C# DateTime property,
> repeated many times over for all of the other variables.

Me too. I only need to bind a SQL attribute to a DateTime edit box
with a couple of mouse clicks.

> > No, object-relational mapping consist in the attempt to equate classes
> > and tables, which is a big blunder. Classes are the same as database
> > domains. Object-relational mapping is a fatally flawed concept.
> >
> Object-relational mapping is about mapping the results of SQL queries to the
> properties of in-memory objects.

This is too general. To map a table directly to a visual control is
not called O/R mapping.

See this:

Often, the interface for object-relational mapping products is the
same as the interface for object databases.

http://www.service-architecture.com/object-relational-mapping/articles/object-relational_mapping_or_mapping_definition.html

By object databases they mean network databases. That's what is wrong.

> I agree with you that mapping objects
> one-to-one with individual database tables is a bad idea.

As bad as mapping objects one-to-many with multiple database tables.

> I agree that
> there have been products that required this, and I agree that they were bad
> products. How is it that you came to believe that that was all that
> object-relational mapping was about?

All I readed about O/R mapping was about that, and I readed a lot. I
can provide dozens of links if you want.

This is probably the worst crap I have found:

http://www.agiledata.org/essays/mappingObjects.html

> Look, we need to bring data into in-memory objects so we can process it

No!

We need to bring data into application objects so we can show the data
to the users and get new data from the users. DBMSs are for data
management and applications for presentation and communication.

>, we
> have business requirements, we need to process payrolls, generate extract
> files, calculate how much we have to pay our customers, etc.

DBMSs are intended to calculate these things.

Regards
  Alfredo



Relevant Pages

  • Re: Want to write your SQL statements and even stored procedures in pure C#?
    ... "Unlike other object-relational mapping tools available on the market, ... solely on CRUD operations and pre-defined relationship models, ... does not itself provide any provision for O/R mapping. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Storing objects in SQL Server table
    ... > mapping the values of the attributes. ... LLBLGen Pro, ... db and creates the classes you need, complete with O/R mapping features. ... My .NET Blog: http://weblogs.asp.net/fbouma ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Storing objects in SQL Server table
    ... > technique you're looking for is 'O/R mapping'. ... > Frans. ... If you have already the tables in SQL Server is a question of ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Building expression trees to filter derived entity classes
    ... up the inheritance correctly in your LINQ to SQL mapping? ... you project the your LINQ to SQL entity objects onto some other POCO ... LINQ to SQL is still trying to process the entire query, ...
    (microsoft.public.dotnet.languages.csharp)
  • DataSet & DataGrid with joined tables
    ... I am working with a very typical pair of tables in a SQL Server ... database, one is a detail table, the other a mapping table ... insert that data into the underlying database. ... The problem statement ...
    (microsoft.public.dotnet.framework.adonet)