Cannot deserialize string from BsonType ObjectId in MongoDb C#

前端 未结 2 1527
误落风尘
误落风尘 2021-02-18 22:31

I am getting error \"Cannot deserialize string from BsonType ObjectId\" while trying to get all the record from MongoDb in C# WebAPI

My Id is



        
2条回答
  •  温柔的废话
    2021-02-18 23:02

    Guid.NewGuid() will not produce ObjectId. Object Id is 12 byte data structure and Guid produce 16byte hex string (without '-')

    You should remove attribute [BsonRepresentation(BsonType.ObjectId)]

    You can use any string as Id in your entity for example 'HiDude' and any string in utf8 format.

提交回复
热议问题