I'd like to store data in an existing table called Cars
using this code:
var carlist = new Car { brand = "Nissan", model = "GTR", constructionyear = 2019, milage = 35000 };
context.Cars.Add(carlist);
context.SaveChanges();
When running the app the following SQL statement is generated:
> INSERT [dbo].[Cars]([brand], [model], [constructionyear], [milage])
> VALUES (@0, @1, @2, @3) SELECT [carID] FROM [dbo].[Cars] WHERE
> @@ROWCOUNT > 0 AND [carID] = scope_identity()
> -- @0: 'Nissan' (Type = AnsiString, Size = 60)
> -- @1: 'GTR' (Type = AnsiString, Size = 60)
> -- @2: '2019' (Type = Int32)
> -- @3: '35000' (Type = Int32)
> -- Executing at 16.01.2022 20:46:31 +01:00 'UB_CarPool.exe' (CLR v4.0.30319: UB_CarPool.exe): Loaded
> 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Caching\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Caching.dll'.
> Skipped loading symbols. Module is optimized and the debugger option
> 'Just My Code' is enabled.
> -- Completed in 16 ms with result: SqlDataReader
>
> Committed transaction at 16.01.2022 20:46:31 +01:00 Closed connection
> at 16.01.2022 20:46:31 +01:00
After closing the app, the table is still empty.
Could someone help me to understand what's going wrong?
PS: it's database first and the entity data model was made by EF Designer