Reflection is slow. That line probably doesn't help your performance :
var model = (T)Activator.CreateInstance(typeof(T));
I notice that you always create your instance with parameterless constructors. So you could add the type constraint new()
in your class. That means you could do :
var model = new T();
That'd be faster and well... clearer.
You also use reflection to get properties. But you do it every time you make a query. You should cache this, after all, there's not much chances an object will gain properties during runtime :p (By caching, I mean adding your properties once in a static
dictionary, so you won't need to get them twice or more.)
Overall, you're using reflection to map properties to your object, and that is probably the cause of your problem. You should use another solution. For example, I recently wrote a question about a property mapper using compiled Linq expressions. That solution is much faster than using reflection (like, way faster) but someone wrote an answer that proposes another solution another solution I didn't explore yet that is even faster to map properties.
Overall, your performance problem is very probably related to the use of reflection!
Reflection is slow. That line probably doesn't help your performance :
var model = (T)Activator.CreateInstance(typeof(T));
I notice that you always create your instance with parameterless constructors. So you could add the type constraint new()
in your class. That means you could do :
var model = new T();
That'd be faster and well... clearer.
You also use reflection to get properties. But you do it every time you make a query. You should cache this, after all, there's not much chances an object will gain properties during runtime :p (By caching, I mean adding your properties once in a static
dictionary, so you won't need to get them twice or more.)
Overall, you're using reflection to map properties to your object, and that is probably the cause of your problem. You should use another solution. For example, I recently wrote a question about a property mapper using compiled Linq expressions. That solution is much faster than using reflection (like, way faster) but someone wrote an answer that proposes another solution I didn't explore yet that is even faster to map properties.
Overall, your performance problem is very probably related to the use of reflection!
Reflection is slow. That line probably doesn't help your performance :
var model = (T)Activator.CreateInstance(typeof(T));
I notice that you always create your instance with parameterless constructors. So you could add the type constraint new()
in your class. That means you could do :
var model = new T();
That'd be faster and well... clearer.
You also use reflection to get properties. But you do it every time you make a query. You should cache this, after all, there's not much chances an object will gain properties during runtime :p (By caching, I mean adding your properties once in a static
dictionary, so you won't need to get them twice or more.)
Overall, you're using reflection to map properties to your object, and that is probably the cause of your problem. You should use another solution. For example, I recently wrote a question about a property mapper using compiled Linq expressions. That solution is much faster than using reflection (like, way faster) but someone wrote an answer that proposes another solution I didn't explore yet that is even faster to map properties.
Overall, your performance problem is very probably related to the use of reflection!
Reflection is slow. That line probably doesn't help your performance :
var model = (T)Activator.CreateInstance(typeof(T));
I notice that you always create your instance with parameterless constructors. So you could add the type constraint new()
in your class. That means you could do :
var model = new T();
That'd be faster and well... clearer.
You also use reflection to get properties. But you do it every time you make a query. You should cache this, after all, there's not much chances an object will gain properties during runtime :p (By caching, I mean adding your properties once in a static
dictionary, so you won't need to get them twice or more.)
Overall, you're using reflection to map properties to your object, and that is probably the cause of your problem. You should use another solution. For example, I recently wrote a question about a property mapper using compiled Linq expressions. That solution is much faster than using reflection (like, way faster) but someone wrote an answer that proposes another solution I didn't explore yet that is even faster to map properties.
Overall, your performance problem is very probably related to the use of reflection!