我在很長一段時間遇到問題。讓我們想象這個例子:Microsoft.EntityFrameworkCore.dll中發生類型爲「Microsoft.EntityFrameworkCore.DbUpdateException」的異常。
public class Coordinate {
public int id {get;set;}
public int x {get;set;}
public int y {get;set;}
}
public class Planet {
public int id {get;set;}
public string name {get;set;}
public Coordinate coordinate {get;set;}
}
我已經創建了兩個模型,並且模型Planet具有模型座標作爲屬性。 現在想象一下代碼中的某處,我創建了一個座標,並將其存儲在數據庫中。 想象這是座標:
Coordinate c = new Coordinate();
c.x = 1;
c.y = 2;
然後我把它添加到我的數據庫,並將其保存。
但是,當我創建一個星球,我做的:
planet.coordinate = c;
然後我試着將它添加到數據庫中,我有以下錯誤:
An exception of type 'Microsoft.EntityFrameworkCore.DbUpdateException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code
Additional information: An error occurred while updating the entries. See the inner exception for details.
我知道我可以改變屬性public Coordinate coordinate
到public int coordinate_id
但我想用座標模型來代替。
我使用ASP NET CORE 1.0
Cumps
「詳情請參見內部異常。」那麼它說什麼? – DavidG