Hi I use MySQL Connector/Net 6.3.5 and Entity Framework 4.1.
In DB I have table with arround 320 000 rows I do simple query by column.
I have litlle problem with performance. It exist some technique or methods how speed up query?
Query timeout is about 6.3 seconds, server is not local.
Here is method which I use :
/// <summary>
/// select podla kluca
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public TEntity SelectByKey(string key)
{
// First we define the parameter that we are going to use the clause.
var xParam = Expression.Parameter(typeof(TEntity), typeof(TEntity).Name);
MemberExpression leftExpr = Expression.Property(xParam, KeyProperty);
Expression rightExpr = Expression.Constant(key);
BinaryExpression binaryExpr = Expression.Equal(leftExpr, rightExpr);
//Create Lambda Expression for the selection
Expression<Func<TEntity, bool>> lambdaExpr = Expression.Lambda<Func<TEntity, bool>>
(binaryExpr, new ParameterExpression[] { xParam });
//Searching ....
IList<TEntity> resultCollection = ((IRepository<TEntity, TCtx>)this).SelectAll(new Specification<TEntity>(lambdaExpr));
if (null != resultCollection && resultCollection.Count() > 0)
{
//return valid single result
return resultCollection.First();
}
return null;
}
How About replacing your last few lines (Sorry I have not tested it) but just from top of my head.