Open Swahhillie opened 2 years ago
You could check if the value exists in separate queries.
But the query could be also like this:
var notExists = new Query()
.WhereNotExists(q => q.From("tree_prototype")
.Where("name", data.name))
.FromRaw("( VALUES ( ?, ? )) AS t ( name, height )", data.name, data.height)
.Select("t.name", "t.height");
var insert = new Query("tree_prototype")
.AsInsert(new[] { "name", "height" }, notExists);
db.Execute(insert);
Refer to this Microsoft documentation.
I am trying to generate the following query:
But all I am able to get sqlkata to make is this:
The second query will throw because of a unique constraint failure on the name column.
Using the following code:
How would I write the code to generate the desired SQL code?