You can use Andrew's suggestion to use ObjectId? for your C# data
type.
Here's a sample program:
File at:
https://gist.github.com/4bb33e2c799a6865b71b
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
namespace NullObjectId {
public class C {
public ObjectId? Id;
public ObjectId? Property;
}
public static class Program {
public static void Main(string[] args) {
var server = MongoServer.Create("mongodb://localhost/?
safe=true");
var database = server["test"];
var collection = database.GetCollection<C>("test");
collection.RemoveAll();
collection.Insert(new C { Id = null, Property = null });
collection.Insert(new C { Id = ObjectId.GenerateNewId(),
Property = null });
collection.Insert(new C { Id = ObjectId.GenerateNewId(),
Property = ObjectId.GenerateNewId() });
foreach (var document in collection.FindAll()) {
Console.WriteLine("Id = {0}, Property = {1}",
document.Id, document.Property);