2
我遇到'System.OverflowException' in MongoDB.Bson.dll
(Additional information: Arithmetic operation resulted in an overflow.
),沒有想法調用UpdateOneAsync
時候爲什麼:發生OverflowException雖然沒有算術操作完成
CarSpec spec = GetSpec();
var updateDefinition = Builders<Cars>.Update.Set(c => c.Spec, spec);
IMongoCollection<CarBatch> carsBatch = GetCarsBatch();
var result = await carsBatch.UpdateOneAsync(c => c.Id == car.Id, updateDefinition);
這些都是重要的數據結構:
public class Car {
public string Id;
public ServiceVersion CurrentVersion = new ServiceVersion();
public CarSpec Spec = new CarSpec();
public List<StatusNotice> StatusNotifications = new List<StatusNotice>();
}
public class CarSpec {
internal const uint InitialChasisNumber = 1000000000;
public uint ChasisNumber = InitialChasisNumber;
public uint DoorsCount;
}
什麼可能是錯的?
我更新了正確的字段中的問題,但你得到它反正...我的'CarSpec GetSpec()''返回其ChasisNumber'是大於'2^31'。 – Tar
int32範圍是-2,147,483,648到2,147,483,647,而uint範圍是0到4,294,967,295。在這種情況下,您可以使用int64,範圍是-9,223,372,036,854,775,808到9,223,372,036,854,775,807,並且可以爲您的代碼正常工作。 :) –