How to pass ObjectId from MongoDB in MVC.net

后端 未结 5 471
野的像风
野的像风 2020-12-06 11:55

I\'m starting a new project with Mongo, NoRM and MVC .Net.

Before I was using FluentNHibernate so my IDs were integer, now my IDs are ObjectId. So when I have an Edi

5条回答
  •  甜味超标
    2020-12-06 12:27

    Did you know you can use the [MongoIdentifier] attribute to make any property act as the unique key?

    I've been solving this issue by borrowing a technique from WordPress by having every entity also be represented by a "url slug" property and decorating that property with [MongoIdentifier].

    So if I had a person named Johnny Walker I'd create a slug of "johnny-walker". You just have to make sure these url slugs stay unique and you get to keep clean urls without ugly object ids.

提交回复
热议问题