views:

157

answers:

1

Hi, in a MVC application it is quite common to have a list of objects that you click to see detail and / or edit. When using a relational db, this is achieved by using the primary key or id:

<%= Html.ActionLink(dinner.Title, "Details", new { id=dinner.DinnerID }) %>

How would you do this using an oodb such as db4o?

Thanks!

+2  A: 

There are three possibilities:

  • Using the internal object-id. Db4o gives each object an internal id, which you could use. However this id changes as soon as you defragment the database. Therefore it’s not usable for permanent-links.

  • Using the Db4o-GUID: Db4o can generate a UUID for each object. You could use this as id. However this UUID is huge.

  • Use you’re own ID. You could assign some ID for your objects yourself. There are different possibilities. For example you could create a Guid for each object. Or use the HiLo-Algorithm.

Gamlor
pretty much what I thought. I think I'll go with the Guid. Thanks!
Be carefull, older versions of db4o handle Guids quite bad. The current 7.12-version handels Guids way more efficent.
Gamlor
I'm using 7.4. Hows that for id's?
System.Guid is a value-type. And in as soon as you store it with db4o 7.4 it is boxed to a object. This makes querying for the right Guid quite inefficient. Furthermore db4o gets confused by the boxing/unboxing of the GUID's, and may store it twice. It still works fine, but you've then unnecessary date stored in the database. So you could upgrade to 7.12, but that version is still a beta.Or you could store the guid as string-field.Or you can live with the issues of the System.Guid-handling of db4o 7.4
Gamlor