Dynamic object - Tidy property names?

I use some code to execute SQL and return IEnumerable from dynamic objects. The code is here if you want to see it.

I have a table with a column name, for example APPLICATION_NAME;

In my object, I have to reference it like this:

var results = ReturnResults("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=rawdb;Data Source=mypc", "SELECT * FROM APPLICATIONS"); string name = results.First().APPLICATION_NAME; 

Is there a way to get property names to solve something more neat? i.e.

 string name = results.First().ApplicationName; 

thanks

+4
source share
1 answer

There are several ToCamelCase() extensions (just google it ). But if you implement it into your dynamic object. How do you know what a brilliant name you should take for an ugly column name?

Instead, you should rewrite the select statement to return beautiful names, instead of embedding any algorithm in a dynamic object. How about this statement:

 SELECT APPLICATION_NAME as 'ApplicationName' FROM APPLICATIONS 

This way, everyone who reads the sql statement understands how to access columns through a dynamic object.

+2
source

Source: https://habr.com/ru/post/1338721/


All Articles