4

Trying to do a:

var list = new List<MyType>();
list.Add(new MyType() { PK1 = 1, PK2 = 2 });
list.Add(new MyType() { PK1 = 1, PK2 = 3 });
Database.Open().MySchema.MyTable.Upsert(list);

Nothing seems to happen, do i need to do a foreach or can i achieve this some how?

Lars Stenberg
  • 241
  • 1
  • 11

2 Answers2

5

This will work, or any other enumeration of the result.

Database.Open().MySchema.MyTable.Upsert(list).ToArray();

Although it will not generate a batch SQL query, there will be a lot of queries to the database, at least for SQL Server.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jakob Rasmussen
  • 171
  • 1
  • 5
1

Does

Database.Open().MySchema.MyTable.Upsert( new MyType { PK1 = 1, PK2 = 2 } );

work?

ToArray() -

var list = new List<MyType>();
list.Add(new MyType() { PK1 = 1, PK2 = 2 });
list.Add(new MyType() { PK1 = 1, PK2 = 3 });
Database.Open().MySchema.MyTable.Upsert(list.ToArray());
Sam Leach
  • 12,746
  • 9
  • 45
  • 73