2015-08-14 19 views
2

我遇到'System.OverflowException' in MongoDB.Bson.dllAdditional 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; 
} 

什麼可能是錯的?

回答

2

與uint數據類型沒有任何關係嗎?嘗試更新爲int並告訴我們結果。

正如您在MongoDB文檔中看到的,支持的可用BSON類型不包含uint32。

檢查在這裏:http://docs.mongodb.org/manual/reference/bson-types/

+1

我更新了正確的字段中的問題,但你得到它反正...我的'CarSpec GetSpec()''返回其ChasisNumber'是大於'2^31'。 – Tar

+1

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,並且可以爲您的代碼正常工作。 :) –