title: .NET, Layered Architecture & MongoDB - What to use as ID?
body: <p>I'm developing a .NET web service while trying to maintain a layered architecture that keeps my Models in one project and DB access (DAL) in a different one. The idea behind this is that if I have to change the DB technology, it's just a matter of creating a differnet DAL, while the rest of the application remains unchanged.</p>
  
  <p>In the data-access layer that I'm developing, I am using  <a href="http://docs.mongodb.org/ecosystem/drivers/csharp/" rel="nofollow noreferrer">Mongo DB C# Driver</a>.</p>
  
  <p>I've seen that:</p>
  
  <ul>
  <li><p>Properties named "ID" will be mapped by the C# driver as the database's "_id" (<em>Convention over configuration</em>);</p></li>
  <li><p>Int + Auto-increment in MongoDB <a href="https://stackoverflow.com/questions/6645277/should-i-implement-auto-incrementing-in-mongodb">is not a good idea</a>;</p></li>
  <li><p>Using Guid's as ID in MongoDB <a href="https://stackoverflow.com/questions/11355792/with-mongodb-and-guids-for-the-id-of-documents-what-is-efficient-way-to-store-th">isn't a good idea either</a>;</p></li>
  <li><p>The recommended data type for the ID of documents stored in MongoDB is <a href="http://docs.mongodb.org/manual/reference/object-id/" rel="nofollow noreferrer"><code>ObjectID</code></a>. The C# driver provides a class to represent this;</p>
  
  <ul>
  <li>However, if I use this data type (from <code>MongoDB.Bson</code>) in my Models, then they will become dependent on the MongoDB C# Driver and I don't want that: I want my models to be DB-independent; only my DALs can depend on whatever data access technologies I use.</li>
  </ul></li>
  </ul>
  
  <p>So what data type should I use for my POCOs' IDs in order to have guarantee uniqueness in the DB? Would a string representation of a Guid be horrible in terms of performance?</p>
  
  <p>Your feedback is welcome.</p>