I'm using dapper.net to execute an insert as follows:
var columns = conn.Query("INSERT INTO MyTable" + "(Col1, Col2, Col3)" + "VALUES (@Col1, @Col2, @Col3)" + "SELECT Id, ComputedColumn FROM MyTable WHERE Id = scope_identity()", myObj).Single(); myObj.Id = columns.Id; myObj.ComputedValue = columns.ComputedColumn;
The query succeeds, but an exception is thrown at
myObj.ComputedValue = columns.ComputedColumn; saying
'System.Dynamic.DynamicObject' does not contain a definition for 'ComputedColumn'
As you might have gathered, ComputedColumn is a computed column on the table, which is why I'm returning it after the insert along with the Id. Any idea why this would be failing?
Figured it out -- I had a instead-of-insert trigger on this table. The trigger was returning the Id in order to play nice with Entity Framework (which I've since switched over to dapper).
SELECT Id, ComputedColumn FROM MyTable WHERE Id = scope_identity() was actually not even returning a row, but dapper was correctly loading the Id returned by the trigger. Changed the trigger to return Id and ComputedColumn and everything works great!