11

This is probably a very simple answer, but i'm new to RavenDb, so i'm obviously missing something.

I've got a basic object with the default convention for id:

public string Id { get; set; }

When i save it to the document store, i see it gets a value of like:

posts/123

Which is fine, but...how do i generate a URL like this:

www.mysite.com/edit/123

If i do this:

@Html.ActionLink("Edit", "Posts", new { id = @Model.Id })

It will generate the followiung URL:

www.mysite.com/edit/posts/123

Which is not what i want.

Surely i don't have to do string manipulation? How do people approach this?

RPM1984
  • 72,246
  • 58
  • 225
  • 350

3 Answers3

16

RPM1984, There are several ways you can deal with that.

1) You can modify your routing to handle this:

routes.MapRoute(
    "Default",                                                // Route name
    "{controller}/{action}/{*id}",                            // URL with parameters
    new { controller = "Home", action = "Index", id = "" });  // Parameter defaults

This will allow MVC to accept parameters with slashes in them

2) You can modify the default id generation strategy:

 documentStore.Conventions.IdentityPartsSeparator = "-";

This will generate ids with:

posts-1 posts-2 etc

See also here:

http://weblogs.asp.net/shijuvarghese/archive/2010/06/04/how-to-work-ravendb-id-with-asp-net-mvc-routes.aspx

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • Thanks Ayende - i'll go with option 2. BTW, i missed your Raven webinar last night because it kept saying "Invalid ID, please try again". :( Any plans to post the audio/video for the webinar somewhere? – RPM1984 Sep 09 '11 at 23:25
3

You can simply use ...

int Id;

..instead of ...

string Id;

in your entity classes :)

Korayem
  • 12,108
  • 5
  • 69
  • 56
1

Actually you have to extract the integer value out of the documents string-based id. This is because raven can actually handle any kind of Id, not necessarily a HILO-generated integer (this is default if you do not specify an id by your own).

Take a look at RaccoonBlog sample. There is a helper class "RavenIdResolver" inside which makes it really easy to get the numeric id out of the documents-id.

Daniel Lang
  • 6,819
  • 4
  • 28
  • 54