Use table-object as a part of SQL Query
During runtime I build an object which is essentially a wrapper over in-memory table:
col1 | ... | colN |
val11 | ... | valN1 |
val12 | ... | valN2 |
I want to use this object as a part of INSERT or UPDATE queries, based on a value of some column (the main use case one of the columns is an ID value)
What's the best way to expose the object to SQL?
I have complete control over object class, so if I need to add something (or even change runtime internals), it's no problem.
Object may have different columns depending on runtime situation, but during one query execution the fields are constant.
I'm interested in the most performant solution.
I want to write queries like this
INSERT INTO table (Name,Age) SELECT Name,Age FROM myObject
And:
UPDATE table AS t
SET t.Name = obj.Name
FROM myObject AS obj
WHERE t.Id = obj.Id