❔ Generating SQL strings in a method?
Hello there, I want to create a method that can generate me a SQL string based upon the parameters passes
I've thought of having a Table Name, Table Obj (obj data is update by entry form), Key Field name and key value
that would be something like
public static ExtSQL(this DbContext _context, string Table_Name, dynamic TableObj, string KeyFileld, string KeyValue) this method will check if given value exist in Table or not (this part is done) but when it comes to generating insert SQL or update i cant figure out how or what ways should take to achieve this.
public static ExtSQL(this DbContext _context, string Table_Name, dynamic TableObj, string KeyFileld, string KeyValue) this method will check if given value exist in Table or not (this part is done) but when it comes to generating insert SQL or update i cant figure out how or what ways should take to achieve this.
9 Replies
So you want to create your own ORM for... some reason
kind of
Why not just use an ORM, then?
Entity Framework is right there
it is but it lacks add or update and also that doesn't fit with want it want to achieve in the project i'm poring on
What do you mean it lacks add or update..?
in this case i have to set each prop... i have 50 to 150 props in each table
There are other ways of performing updates
or
Or, sure, you can go with your idea
It'll be a lot of string building and type-unsafe code, though
mostly i my data in in string or decimal that too have no way of putting special chars... that are already checked in front end
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.