Hi was trying to find the ORM with the best performance to use in our new project. My final choice became Dapper. We also need to have our application to include the following features (at least) which prevent us from hard coding the SQL queries to pass to Dapper
- Database independent
- Run time entities definition
I thought about writing an SQL generator for Dapper but I am not sure the approach I am following is the best:
- Declare an Interface with methods signature. The implementation corresponds to the Database system to be used (SQL Server/ MySQL/ PostgreSql/ DB2/ Oracle/ etc...).
Create Database XML Schema using the following format:
<sqltable name="Foo"> <sqlfield name="ID" primarykey="1" /> <sqlfield name="Name" /> <sqlfield name="Surname /> <sqlfield name="etc" /> <sqlreference name"KooID" table="Koo" field="ID" /> </sqltable>
Generate classes/entities using the XML provided above (allowing the extension of the schema on runtime). Objects created are POCO.
Implement methods that loop on the properties of the current entity (using reflexion) and generate SQL statements where property is not null:
String GetInsert(object currentEntity) return: "INSERT INTO Foo (ID, Name) VALUES (1, 'BooBoo')"
The implementation will include at least
SELECT INSERT INTO UPDATE DELETE JOIN /*(using references like the KooID above)*/ WHERE /*(using filter expressions)*/
Can you think of any backwards/disadvantages of this approach? Can you recommend any improvements?
Thank you!