I have an object with properties names that exactly name the field names inside the DB table but I'm not sure how to insert it. The only thing different is the DB table name. So it's an object with a name of different model/mapped table but I want it to be inserted into a table with a different name than the model. I tried this:
var val = info.FooBarObj;
conn.Execute("insert DBInformation(val) values(@val)", new { val = val });
Where e.g.
Object is FooBarObj
and properties are int Id, string Foo, string Bar
and the DBInformation
has the field names: Id, Foo, and Bar
but the table isn't called FooBarObj
, it's called DBInformation
.
How can I insert something like this? I'm using Dapper
EDIT:
Can I have two table attributes for FooBar model?
E.g. [Table("DBInformation")]
and [Table("FooBar")]
.
I have a weird edge case where I want to insert into FooBar if this scenario occurs, if another scenario occurs, insert into DBInformation. That's the problem I'm currently facing and thus that's why I can't just add the attribute and be done with for this problem.