I am going with the Entity Framework code first approach and am finding that queries to grab just 350 records or so is taking about 8 seconds. How can I speed this up? Is this Universe or Entity Framework that is being slow?
Entity Framework 5.0 U2.Data.Client 1.2.1 .Net Framework 4.5.1
RAMContext looks something like this :
public class RAMContext : DbContext
{
public RAMContext() { }
public DbSet<Policy> Policies { get; set; }
}
Here is the code to grab the entities :
List<Policy> policies = null;
Database.SetInitializer<RAMContext>(null);
using (RAMContext context = new RAMContext())
{
policies = (from p in context.Policies
where p.AGENT_NO == id
select p).ToList();
}
Here is the connection string :
<add name="RAMContext" connectionString="Database=<account>;UserID=<userid>;Password=<pwd>;Server=<server>;Pooling=false;ServerType=universe;ConnectTimeout=360;SleepAfterClose=300;PersistSecurityInfo=true" providerName="U2.Data.Client" />
AGENT_NO is indexed and the same query ran directly on the DB from TCL finishes almost instantly.
EDITED After the comments from Rajan I tried the following :
policies = (from p in context.Policies
where p.AGENT_NO == id
select new PolicyModel
{
//Type = PolicyModel.Types)StringValue.GetEnumValueByStringValue(typeof(PolicyModel.Types), p.TYPE),
Insured = p.INSURED,
City = p.CITY,
State = p.STATE,
CancelDate = p.CANC_DT
//IsNew = PickHelper.PickYNNullToBool(p.NEW_RENEW_FLG)
});
I am able to make this select in under 3 seconds now, it appears. I also rebuilt the index on AGENT_NO and I believe that helped considerably.
Trying your second suggestion I get the following exception :
An exception of type 'System.IndexOutOfRangeException' occurred in U2.Data.Client.dll but was not handled in user code
Additional information:
Invalid index -1 for this U2ParameterCollection with Count=0.