Skip to content

Instantly share code, notes, and snippets.

@ivanfioravanti
Forked from efbenson/gist:4259486
Last active December 15, 2015 13:29
Show Gist options
  • Save ivanfioravanti/5268017 to your computer and use it in GitHub Desktop.
Save ivanfioravanti/5268017 to your computer and use it in GitHub Desktop.
Automapper for MongoDB ObjectIds
Mapper.CreateMap<List<ObjectId>, List<string>>().ConvertUsing(o => o.Select(os => os.ToString()).ToList());
Mapper.CreateMap<List<string>, List<ObjectId>>().ConvertUsing(o => o.Select(os => ObjectId.Parse(os)).ToList());
Mapper.CreateMap<ObjectId, string>().ConvertUsing(o => o.ToString());
Mapper.CreateMap<string, ObjectId>().ConvertUsing(s => ObjectId.Parse(s));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment