ASP.NET Core已有数据库,却新建项目

发布时间 2023-10-25 13:12:12作者: JohnYang819

ASP.NET Core已有数据库,却新建项目,只需要构造出相应的类,DbContext,然后直接add-migration init即可!!而不用执行update-database,执行后者会报错:Error Number:2714,State:6,Class:16
There is already an object named 'xxxxxx' in the database.
另外,注意主键到底是int,还是long,这个错了,后面取数据,会报错System.InvalidCastException:“Unable to cast object of type 'System.Int64' to type 'System.Int32'.”