RavenDb with ASP.NET MVC 3 - How to generate URL with ID?

孤街醉人 提交于 2019-12-05 00:55:44

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

You can simply use ...

int Id;

..instead of ...

string Id;

in your entity classes :)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!