@@ -77,9 +77,45 @@ static async Task Main(string[] args)
7777 using ( var conn = new NpgsqlConnection ( connString ) ) {
7878 conn . Open ( ) ;
7979
80- await TestBasics ( conn ) ;
81- await TestUnnestAsync ( conn ) ;
82- await TestInsertUsingEntityFramework ( conn ) ;
80+ // await TestBasics(conn);
81+ // await TestUnnestAsync(conn);
82+ // await TestInsertUsingEntityFramework(conn);
83+ await TestInsertWithDuplicateKeyConflict ( conn ) ;
84+ }
85+ }
86+
87+ private static async Task TestInsertWithDuplicateKeyConflict ( NpgsqlConnection conn )
88+ {
89+ using ( var cmd = new NpgsqlCommand ( "drop table if exists test.test" , conn ) )
90+ {
91+ await cmd . ExecuteNonQueryAsync ( ) ;
92+ }
93+ string createTable = @"
94+ CREATE TABLE test.test (
95+ id text default gen_random_text_uuid() primary key,
96+ datetime timestamp with time zone
97+ )" ;
98+ using ( var cmd = new NpgsqlCommand ( createTable , conn ) )
99+ {
100+ await cmd . ExecuteNonQueryAsync ( ) ;
101+ }
102+ CrateContext . ConnectionString = conn . ConnectionString ;
103+ var entries = new List < TestEntity > ( ) ;
104+ using ( CrateContext context = new ( ) ) {
105+ for ( int i = 0 ; i < 4 ; i ++ )
106+ {
107+ var entry = new TestEntity ( ) ;
108+ context . Test . Add ( entry ) ;
109+ entries . Add ( entry ) ;
110+ }
111+ await context . SaveChangesAsync ( ) ;
112+ }
113+
114+ using ( CrateContext context = new ( ) ) {
115+ foreach ( var entry in entries ) {
116+ context . Test . Add ( entry ) ;
117+ }
118+ await context . SaveChangesAsync ( ) ;
83119 }
84120 }
85121
0 commit comments