Search code examples
asp.net-mvc-2db4o

Handling ID's with db4o and ASP.NET MVC2


So, i'm looking at the TekPub sample for ASP.NET MVC2 (http://mvcstarter.codeplex.com/) using DB4o and there are a bunch of templates to create controllers etc, the generated code looks like:

    public ActionResult Details(int id)
    {
        var item = _session.Single<Account>(x=>x.ID == id);
        return View(item);
    }

Now, my understanding is that using DB4o or a simliar object database that ID's are not required, so how/what exactly do I pass to enable this kind of templated code to function?

UPDATE: Both answers were useful, I have modifed the templates to use GUID as the ID. I will add any relevant code/notes here once I see how it works out.

UPDATE: So, what I have done (which works exactly as I would expect) is 1. Add an ID to my model i.e.

public Guid ID { get; set; }
  1. Initialize the Guid in the class constructor like so

    ID = Guid.NewGuid();

and that's it, all working.


Solution

  • In the MVCStarter the method you are describing is actually:

    public ActionResult Details(string id)
    {
    var item = _session.Single<Account>(x=>x.ID == id);
    return View(item);
    }
    

    And id is a string representation of a Guid.

    db4o to the best of my knowledge won't generate an int ID automatically...it has no idea what the last one was. So a Guid is used on the object and set on the constructor.