您好我使用 MySQL Connector/Net 6.3.5 和 Entity Framework 4.1。
在数据库中,我有大约 320 000 行的表,我按列进行简单查询。
我对性能有一点问题。它存在一些如何加快查询速度的技术或方法?
查询超时时间约为 6.3 秒,服务器不在本地。
这是我使用的方法:
/// <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;
}